You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Dispatches a message to all registered Stores. This process is done synchronously, all registered `Store`s are passed this message and all components are re-evaluated (efficiently). After a dispatch, a Reactor will emit the new state on the `reactor.changeEmitter`
Allows multiple dispatches within the `fn` function before notifying any observers.
817
+
818
+
```js
819
+
reactor.batch(function() {
820
+
reactor.dispatch('addUser', { name:'jordan' })
821
+
reactor.dispatch('addUser', { name:'james' })
822
+
})
823
+
824
+
// does a single notify to all observers
825
+
```
826
+
800
827
#### `Reactor#evaluate(Getter | KeyPath)`
801
828
802
829
Returns the immutable value for some KeyPath or Getter in the reactor state. Returns `undefined` if a keyPath doesn't have a value.
@@ -838,6 +865,27 @@ reactor.observe([
838
865
])
839
866
```
840
867
868
+
#### `Reactor#serialize()`
869
+
870
+
Returns a plain javascript object representing the application state. By defualt this maps over all stores and returns `toJS(storeState)`.
871
+
872
+
```js
873
+
reactor.loadState(reactor.serialize())
874
+
```
875
+
876
+
#### `Reactor#loadState( state )`
877
+
878
+
Takes a plain javascript object and merges into the reactor state, using `store.deserialize`
879
+
880
+
This can be useful if you need to load data already on the page.
881
+
882
+
```js
883
+
reactor.loadState({
884
+
stringStore:'bar',
885
+
listStore: [4,5,6],
886
+
})
887
+
```
888
+
841
889
#### `Reactor#registerStores(stores)`
842
890
843
891
`stores` - an object of storeId => store instance
@@ -897,19 +945,9 @@ var ThreadSection = React.createClass({
897
945
});
898
946
```
899
947
900
-
### Constructors
948
+
### Store
901
949
902
-
#### `Nuclear.Reactor`
903
-
904
-
```js
905
-
var reactor =newNuclear.Reactor(config)
906
-
```
907
-
908
-
**Configuration Options**
909
-
910
-
`config.debug` Boolean - if true it will log the entire app state for every dispatch.
911
-
912
-
#### `Nuclear.Store`
950
+
#### Constructor
913
951
914
952
```js
915
953
module.exports=newNuclear.Store({
@@ -927,6 +965,49 @@ module.exports = new Nuclear.Store({
927
965
})
928
966
```
929
967
968
+
#### `Store#getInitialState`
969
+
970
+
Defines the starting state for a store. Must return an immutable value. By default it returns an `Immutable.Map`
971
+
972
+
#### `Store#initialize`
973
+
974
+
Responsible for setting up action handlers for the store using `this.on(actionTypes, handlerFn)`
975
+
976
+
#### `Store#serialize`
977
+
978
+
Serialization method for the store's data, by default its implemented as `Nuclear.toJS' which converts ImmutableJS objects to plain javascript.
979
+
This is overridable for your specific data needs.
980
+
981
+
```js
982
+
// serializing an Immutable map while preserving numerical keys
983
+
Nuclear.Store({
984
+
// ...
985
+
serialize(state) {
986
+
if (!state) {
987
+
return state;
988
+
}
989
+
return state.entrySeq().toJS()
990
+
},
991
+
// ...
992
+
})
993
+
```
994
+
995
+
#### `Store#deserialize`
996
+
997
+
Serialization method for the store's data, by default its implemented as `Nuclear.toImmutable' which converts plain javascript objects to ImmutableJS data structures.
998
+
This is overridable for your specific data needs.
999
+
1000
+
```js
1001
+
// deserializing an array of arrays [[1, 'one'], [2, 'two']] to an Immutable.Map
1002
+
Nuclear.Store({
1003
+
// ...
1004
+
deserialize(state) {
1005
+
returnImmutable.Map(state)
1006
+
},
1007
+
// ...
1008
+
})
1009
+
```
1010
+
930
1011
### Utilities
931
1012
932
1013
NuclearJS comes with several utility functions that are exposed on the `Nuclear` variable.
0 commit comments