Skip to content

Instantly share code, notes, and snippets.

@christianalfoni
Last active August 29, 2015 14:24
Show Gist options
  • Save christianalfoni/2cce0e5f05df74cca8af to your computer and use it in GitHub Desktop.
Save christianalfoni/2cce0e5f05df74cca8af to your computer and use it in GitHub Desktop.
import Store from 'immutable-store';
// Any mutations to an immutable-store returns the new mutated store as a result of the operation.
// More info at: https://github.com/christianalfoni/immutable-store
export default function (state = Store({todos: []}), action) {
switch (action.type) {
case ADD_TODO:
return state.todos.push(action.payload);
case REMOVE_TODO:
return state.todos.splice(action.payload, 1);
default:
return state;
}
}
@steida
Copy link

steida commented Jul 8, 2015

In case you want to leverage existing persistent data structure, you can replace whole immutable-store with https://facebook.github.io/immutable-js/docs/#/Map/updateIn method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment