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

ability to call set after value() or generate snapshot at any time #26

Open
ilovett opened this issue Jan 26, 2018 · 1 comment
Open

Comments

@ilovett
Copy link

ilovett commented Jan 26, 2018

It would be helpful to either be able to get a copy of the next immutable state, or at least fetch what the next values will be... This would be helpful for calculating aggregations on new data in reducers...

case: 'ADD_USER':
  next = immutable(state);
  next.set(['path' ,'to', 'users', 'byId', user.id], user);
  next.set(['path', 'to', 'users', 'aggregations', 'totalUsers', Object.keys(next.get(['path', 'to', 'users', 'byId'])).length);
  return next.value();

Getting would be preferable or at least being able to call next.value() then a set then another next.value() if I need to, but I get an error that I can't set after calling value:

Error: Cannot call set after `value`
@ilovett
Copy link
Author

ilovett commented Jan 26, 2018

Another possibility would be having a constructor that recognizes if the passed in data is already an instance of immutable to just make a copy:
EG:

next = immutable(state);
next.set('something', 33);
snapshot = immutable(next).value();
next.set('else', snapshot.something * 2);

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