Skip to content

Commit

Permalink
Allow recycling using the store reference
Browse files Browse the repository at this point in the history
  • Loading branch information
goatslacker committed Apr 26, 2015
1 parent d9e0259 commit 0563352
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/alt/utils/StateFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ export function saveInitialSnapshot(instance, key) {
instance[LAST_SNAPSHOT][key] = state
}

export function filterSnapshots(instance, snapshot, storeNames) {
return storeNames.reduce((obj, storeName) => {
if (!snapshot[storeName]) {
export function filterSnapshots(instance, state, stores) {
return stores.reduce((obj, store) => {
const storeName = store.displayName || store
if (!state[storeName]) {
throw new ReferenceError(`${storeName} is not a valid store`)
}
obj[storeName] = snapshot[storeName]
obj[storeName] = state[storeName]
return obj
}, {})
}
6 changes: 4 additions & 2 deletions src/alt/utils/StoreUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ export function createStoreFromObject(alt, StoreModel, key) {
// create the instance and assign the public methods to the instance
storeInstance = assign(
new AltStore(alt, StoreProto, StoreProto.state, StoreModel),
StoreProto.publicMethods
StoreProto.publicMethods,
{ displayName: key }
)

return storeInstance
Expand Down Expand Up @@ -125,7 +126,8 @@ export function createStoreFromClass(alt, StoreModel, key, ...argsForClass) {
store[alt.config.stateKey] || store[config.stateKey] || null,
StoreModel
),
getInternalMethods(StoreModel)
getInternalMethods(StoreModel),
{ displayName: key }
)

return storeInstance
Expand Down

0 comments on commit 0563352

Please sign in to comment.