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

fix devtools and type middleware properly #167

Merged
merged 1 commit into from
Aug 26, 2020

Conversation

dai-shi
Copy link
Member

@dai-shi dai-shi commented Aug 25, 2020

Close #77

  • devtools follows v3 api (replace flag)
  • devtools works without name (defaults to action)
  • type devtools and redux middleware (a bit messy, can improve?)

Here's how you could use devtools in TS.

const useStore = create<{
  count: number
  increment: () => void
  decrement: () => void
}>(devtools((set, get) => ({
  count: 0,
  increment: () => set({ count: get().count + 1 }, false, "inc"),
  decrement: () => set({ count: get().count - 1 }, false, "dec"),
})));

Here's redux middleware in TS.

const initialState = {                                                          
  grumpiness: 0,                                                                
}                                                                             
                                                                              
const reducer = (  
  state: typeof initialState,  
  action: { type: "INCREASE" | "DECREASE", by: number }                
) => {                                                                          
  switch (action.type) {                                                        
    case "INCREASE": return { grumpiness: state.grumpiness + action.by }        
    case "DECREASE": return { grumpiness: state.grumpiness - action.by }        
    default: return state                                                       
  }                                                                             
}                                                                               
                                                                                
const useReduxStore = create(devtools(redux(reducer, initialState)))            

@dai-shi dai-shi requested a review from drcmda August 25, 2020 11:17
@dai-shi dai-shi merged commit 4675a50 into master Aug 26, 2020
@dai-shi dai-shi deleted the fix-devtools-and-type-middleware branch August 26, 2020 13:59
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.

[devtools] doesn't log actions since v2
1 participant