Skip to content

Commit

Permalink
Fix recycling values that are not set
Browse files Browse the repository at this point in the history
  • Loading branch information
goatslacker committed May 21, 2015
1 parent 540d84c commit 1f8da1b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/alt/utils/StateFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ export function setAppState(instance, data, onStore) {
const store = instance.stores[key]
if (store) {
const { config } = store.StoreModel
if (config.onDeserialize) {
obj[key] = config.onDeserialize(value) || value
}
fn.assign(store[Sym.STATE_CONTAINER], obj[key])
const state = store[Sym.STATE_CONTAINER]
if (config.onDeserialize) obj[key] = config.onDeserialize(value) || value
fn.eachObject(k => delete state[k], [state])
fn.assign(state, obj[key])
onStore(store)
}
}, [obj])
Expand Down
29 changes: 29 additions & 0 deletions test/recycle-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { assert } from 'chai'
import Alt from '../'
import sinon from 'sinon'

export default {
'Recycling': {
'recycles a store with no initial state'() {
const alt = new Alt()
const actions = alt.generateActions('fire')

const store = alt.createStore(function () {
this.bindAction(actions.fire, () => {
this.test = (this.test || 0) + 1
})
}, 'Store')


assert(Object.keys(store.getState()).length === 0, 'store has no state')
actions.fire()

assert(store.getState().test === 1, 'store has some state')

alt.recycle()

assert(Object.keys(store.getState()).length === 0, 'store was emptied')
assert.isUndefined(store.getState().test, 'store was recycled to initial state')
},
}
}

0 comments on commit 1f8da1b

Please sign in to comment.