A helper function to create stores that protect private data from being set from outside. That is the one and only feature of this module.
Use whatever data structures you want inside. You can choose to use immutable data structures from Immutable, Mori, or any other library, or you can choose to return deep clones of your internal data. All this function does is help you keep the internals of your store internal.
npm install --save fluxible-immutable-store
Here is part of a reimplementation of the TodoStore from the Fluxible examples. It uses Facebook's Immutable data structures internally, but that is merely a design choice, not a requirement of this module.
var Immutable = ;var createImmutableStore = ;var TodoStore =;moduleexports = TodoStore;
The variables that represent the store's state can be exposed as accessors. They will have read-only properties created for them. If you use an immutable data structure, then there will be no way to set the property from the outside or to mutate the structure's internal data.
In your component that needs access to the
TodoStore, you would have code
similar to this:
var TodoList = React;
You won't be able to reassign a new object to the
todoStore.todos field, thus
getting you one step closer to an immutable store.
Alternatively, you can set the private data on the
privates object that is
passed into your spec factory function and define the accessors as a simple
array of field names. If you do not need to change the data structure upon
access (such as converting an
then this method is more succinct.
var Immutable = ;var createImmutableStore = ;// Set any private field data as fields on `privates`var TodoStore =;moduleexports = TodoStore;