Skip to content

Commit

Permalink
Add shouldEmitChange config to Store
Browse files Browse the repository at this point in the history
- Provides config to set whether emitChange should be called
  automatically or not after store action listeners
  • Loading branch information
jdlehman committed Jun 12, 2015
1 parent e596786 commit 9f5f4b0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
6 changes: 6 additions & 0 deletions docs/createStore.md
Expand Up @@ -31,6 +31,12 @@ Available configuration options:
`getState` receives the current state and returns a copy of it. You can override this function to provide your own implementation.

#### shouldEmitChange

> shouldEmitChange: boolean
`shouldEmitChange` determines whether `emitChange` should be called automatically after action listeners finish executing. This is set to true by default.

#### onSerialize

`onSerialize` is also called before the store's state is serialized. You may optionally return an object, which will be used directly as the snapshot data for the store. If you do not return anything, the default, [`MyStore#getState()`](stores.md#storegetstate) is used for the snapshot data. See the [serialization](serialization.md) for an example.
Expand Down
4 changes: 2 additions & 2 deletions src/alt/store/AltStore.js
Expand Up @@ -55,15 +55,15 @@ class AltStore {
return actionHandler.call(model, payload.data, payload.action)
}, payload)

if (result !== false && !this.preventDefault) this.emitChange()
if (result !== false && !this.preventDefault && this.StoreModel.config.shouldEmitChange) this.emitChange()
}

if (model.reduce) {
handleDispatch(() => {
model.setState(model.reduce(this.state, payload))
}, payload)

if (!this.preventDefault) this.emitChange()
if (!this.preventDefault && this.StoreModel.config.shouldEmitChange) this.emitChange()
}

this.lifecycle('afterEach', {
Expand Down
3 changes: 2 additions & 1 deletion src/alt/store/index.js
Expand Up @@ -47,7 +47,8 @@ export function createStoreConfig(globalConfig, StoreModel) {
getState(state) {
return fn.assign({}, state)
},
setState: fn.assign
setState: fn.assign,
shouldEmitChange: true
}, globalConfig, StoreModel.config)
}

Expand Down

0 comments on commit 9f5f4b0

Please sign in to comment.