Skip to content

Commit

Permalink
Cache final stores so only one is returned per alt instance
Browse files Browse the repository at this point in the history
  • Loading branch information
goatslacker committed Apr 25, 2015
1 parent 0f6e3e0 commit 838d8cb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/utils/makeFinalStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,7 @@ function FinalStore() {
}

export default function makeFinalStore(alt) {
return alt.createUnsavedStore(FinalStore)
return alt.FinalStore
? alt.FinalStore
: (alt.FinalStore = alt.createUnsavedStore(FinalStore))
}
6 changes: 6 additions & 0 deletions test/final-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { assert } from 'chai'
import sinon from 'sinon'

const alt = new Alt()
const FinalStore = makeFinalStore(alt)

export default {
'FinalStore': {
Expand Down Expand Up @@ -69,5 +70,10 @@ export default {
assert.ok(stateListen.calledOnce, 'final store called once')
assert(stateListen.args[0][0].payload.data === 27, 'the payload was received')
},

'making another final store returns the right store'() {
const store = makeFinalStore(alt)
assert(store === FinalStore)
},
}
}

0 comments on commit 838d8cb

Please sign in to comment.