redux-undo icon indicating copy to clipboard operation
redux-undo copied to clipboard

undoable returns initial state for dynamically added reducer.

Open SunhoY opened this issue 4 years ago • 0 comments

Note: for support questions about the usage of the library, please ask questions on the gitter chat. The issue tracker is reserved for feature requests, bug reports and similar issues. Visit the gitter chat here.

I'm submitting a ...

  • [ ] Bug report
  • [x] Feature request
  • [ ] Docs update
  • [ ] Support request => Please do not submit support requests here, see note at the top of this template.

What is the current behavior/state of the project?

I'm using Reducer Manager from here When I add new reducer and combined it, newly added state would be undefined. for example.

interface ProjectState {
  name: string;
}

const initialState: {
   initialProject: projectState, // this is StateWithHistory,
}

...
// from some place
reducerManager.add('newProject', undoable(...));

Since no actions are dispatched, store state would be same with initialState.

as soon as I dispatch some action, state would be

{
  initialProject: projectState, // existing state
  newProject: newProjectState, // this will be initial value of StateWithHistory
}

luckily, when I started app, redux seems dispatch @@INIT action, so all our states are well formed.

but if I try to dispatch action which interacts with new reducer(which is undoable) right after adding new reducer. because of this statement it returns initialState of StateWithHistory instead of calling reducer. I'm not sure it's a bug or intended behavior.

{
  initialProject: ...existingState,
  newProject: {
    future: [],
    past: [],
    present: ...initialProjectState, // defined initial state in reducer,
    ...,
  }
}

What is the desired behavior?

reducer function should be called with initialState of StateWithHistory and run reducer logic with given action.

If this is a feature request, what is the use case for changing the behavior?

dynamic reducers described above.

use case, Tabs, adding tabs to tab bar, and each tab has it's own history.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via a gist or similar.

Please tell us about your environment:

  • Library version: 1.0.1
  • Redux version: 4.0.5
  • Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Edge XX]
  • Language: [all | TypeScript X.X | ES6/7 | ES5]

Other information

(e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, gitter, etc)

SunhoY avatar Sep 14 '20 11:09 SunhoY