jk-gan / redux-flipper

Redux middleware for React Native for Flipper
MIT License
159 stars 21 forks source link

Support redux-thunk dispatch in flipper-plugin-redux-debugger #47

Closed ljx213101212 closed 3 years ago

ljx213101212 commented 3 years ago

A similar issue can be reproduced by https://github.com/jk-gan/flipper-plugin-redux-debugger/issues/30

I realized that when I use redux-thunk in like below has an issue.

export const setCurrentMode = mode => async dispatch => {
  return dispatch({
    type: SET_CURRENT_MODE,
    payload: {mode},
  });
};

It could be createDebugger didn't handle when action is a function case? https://github.com/jk-gan/redux-flipper/blob/master/src/index.ts#L66

ljx213101212 commented 3 years ago

I propose to add

return (next: any) => (action: any) => {
  if (typeof action === 'function') {
    return action(store.dispatch, store.getState, config);
  }
...

from https://github.com/jk-gan/redux-flipper/blob/master/src/index.ts#L66 to handle when action is a function.

plwai commented 3 years ago

I propose to add

return (next: any) => (action: any) => {
  if (typeof action === 'function') {
    return action(store.dispatch, store.getState, config);
  }
...

from https://github.com/jk-gan/redux-flipper/blob/master/src/index.ts#L66 to handle when action is a function.

This will make a force return and skip the thunk middleware which breaks the thunk functionality. I think there is no issue for this redux-flipper middleware. Instead, the debugger should handle the case when action type is unknown.

@jk-gan Is it a good idea to show thunk action in the debugger?

jk-gan commented 3 years ago

Hi, thanks for the suggestion. we just released version 2.0.0 and the issue should be fixed.