Skip to content

1.1.0 (proposed)

Pre-release
Pre-release
Compare
Choose a tag to compare
@jordangarcia jordangarcia released this 04 Jul 00:34
· 202 commits to master since this release
  • [NEW] added Reactor#serialize, Reactor#loadState, Store#serialize and Store#deserialize methods
  • [NEW] added Reactor#batch to allow batch dispatches before notify observers
  • [FIXED] fix Evaluator locking if getter evaluation errors

API Additions

Reactor#serialize()

Returns a plain javascript object representing the application state. By defualt this maps over all stores and returns toJS(storeState).

reactor.loadState(reactor.serialize())

Reactor#loadState( state )

Takes a plain javascript object and merges into the reactor state, using store.deserialize

This can be useful if you need to load data already on the page.

reactor.loadState({
  stringStore: 'bar',
  listStore: [4,5,6],
})

Store#serialize

Serialization method for the store's data, by default its implemented as `Nuclear.toJS' which converts ImmutableJS objects to plain javascript.
This is overridable for your specific data needs.

// serializing an Immutable map while preserving numerical keys
Nuclear.Store({
  // ...
  serialize(state) {
    if (!state) {
      return state;
    }
    return state.entrySeq().toJS()
  },
  // ...
})

Store#deserialize

Serialization method for the store's data, by default its implemented as `Nuclear.toImmutable' which converts plain javascript objects to ImmutableJS data structures.
This is overridable for your specific data needs.

// deserializing an array of arrays [[1, 'one'], [2, 'two']] to an Immutable.Map
Nuclear.Store({
  // ...
  deserialize(state) {
    return Immutable.Map(state)
  },
  // ...
})