Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ export class PureStore<S, T> {
updaterFn(this.getter(s))
})

this.root.callbacks.forEach(callback=> callback())
this.root.callbacks.forEach(callback=> callback.cb(callback.cbro))
}

storeFor = <X>(getter: (s: T)=>X)=> new PureStore(this, getter)
updaterFor = <X>(getter: (s: T)=>X)=> this.storeFor(getter).update

subscribe = callback=> {
subscribe = (callback,cbReturnObj)=> {
if (this.root != this)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use strict inequality operator !==

throw "Only the top level store can be subscribed to."

this.callbacks.push(callback)
return ()=> this.callbacks.splice(this.callbacks.indexOf(callback), 1)
let index = this.callbacks.push({cb:callback,cbro:cbReturnObj})-1;
return ()=> this.callbacks.splice(index, 1)
}
}

Expand Down