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

undoable returns initial state for dynamically added reducer. #277

Open
1 of 4 tasks
SunhoY opened this issue Sep 14, 2020 · 0 comments
Open
1 of 4 tasks

undoable returns initial state for dynamically added reducer. #277

SunhoY opened this issue Sep 14, 2020 · 0 comments

Comments

@SunhoY
Copy link

SunhoY commented Sep 14, 2020

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
  • 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)

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

No branches or pull requests

1 participant