Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to createAction #110

Merged
merged 14 commits into from
Oct 10, 2024
Merged

Migrate to createAction #110

merged 14 commits into from
Oct 10, 2024

Conversation

jho406
Copy link
Collaborator

@jho406 jho406 commented Oct 10, 2024

This PR migrates most actions over to createAction. The goal of this is

  1. Better typescript support using .match which allows us to use a typescript guard
  2. Easier for users. We previously exposed the const to the user so that they can createAction themselves before using it in a slice. Now they can just import it. For example:
import { createSlice } from '@reduxjs/toolkit'
import { saveResponse, beforeVisit } from '@thoughtbot/superglue'

export const flashSlice = createSlice({
  name: 'flash',
  initialState: {},
  extraReducers: (builder) => {
    builder.addCase(beforeVisit, (state, action) => {
      return {}
    })
    builder.addCase(saveResponse, (state, action) => {
      const { page } = action.payload;

      return {
        ...state, ...page.slices.flash
      }
    })
  }
})

@jho406 jho406 merged commit 38e3d6e into main Oct 10, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant