object-path-immutable
object-path-immutable copied to clipboard
ability to call set after `value()` or generate snapshot at any time
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`
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);