Skip to content

Commit 5b4c86f

Browse files
committed
Update README for 1.1.0 API
1 parent 9dcc5ad commit 5b4c86f

File tree

1 file changed

+93
-12
lines changed

1 file changed

+93
-12
lines changed

README.md

+93-12
Original file line numberDiff line numberDiff line change
@@ -791,12 +791,39 @@ You can read more of the implementation here: [src/evaluator.js](./src/evaluator
791791
792792
### Reactor
793793
794+
#### Constructor
795+
796+
#### `Nuclear.Reactor`
797+
798+
```js
799+
var reactor = new Nuclear.Reactor(config)
800+
// or
801+
var reactor = Nuclear.Reactor(config)
802+
```
803+
804+
**Configuration Options**
805+
806+
`config.debug` Boolean - if true it will log the entire app state for every dispatch.
807+
794808
#### `Reactor#dispatch(messageType, messagePayload)`
795809
796810
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`
797811
798812
ex: `reactor.dispatch('addUser', { name: 'jordan' })`
799813
814+
#### `Reactor#batch(fn)`
815+
816+
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+
800827
#### `Reactor#evaluate(Getter | KeyPath)`
801828
802829
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([
838865
])
839866
```
840867
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+
841889
#### `Reactor#registerStores(stores)`
842890
843891
`stores` - an object of storeId => store instance
@@ -897,19 +945,9 @@ var ThreadSection = React.createClass({
897945
});
898946
```
899947
900-
### Constructors
948+
### Store
901949
902-
#### `Nuclear.Reactor`
903-
904-
```js
905-
var reactor = new Nuclear.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
913951
914952
```js
915953
module.exports = new Nuclear.Store({
@@ -927,6 +965,49 @@ module.exports = new Nuclear.Store({
927965
})
928966
```
929967
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+
return Immutable.Map(state)
1006+
},
1007+
// ...
1008+
})
1009+
```
1010+
9301011
### Utilities
9311012
9321013
NuclearJS comes with several utility functions that are exposed on the `Nuclear` variable.

0 commit comments

Comments
 (0)