New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return the unsubscribe from the subscriber #10

Merged
merged 2 commits into from Dec 7, 2017

Conversation

Projects
None yet
3 participants
@cristianbote
Contributor

cristianbote commented Dec 7, 2017

This introduces the return of unsubscriber, when doing a subscribe.

let store = createStore();
let unsub = store.subscribe(state => modifyState(state));

// After you're done just call the unsubscriber from 'unsub'
unsub();

I often found that this little help goes a long way. Sure it comes with increase in size. Bumps it to 680B but maybe you think it's worth it?

@@ -117,7 +117,7 @@ Creates a new store, which is a tiny evented state container.
let store = createStore();
store.subscribe( state => console.log(state) );
store.setState({ a: 'b' }); // logs { a: 'b' }
store.setState({ c: 'd' }); // logs { a: 'b', c: 'd' }
store.setState({ c: 'd' }); // logs { c: 'd' }

This comment has been minimized.

@cristianbote

cristianbote Dec 7, 2017

Contributor

This is being addressed here: #9

@cristianbote

cristianbote Dec 7, 2017

Contributor

This is being addressed here: #9

@@ -153,7 +155,7 @@ Remove a previously-registered listener function.
##### getState
Retrieve the current state object.
Retreive the current state object.

This comment has been minimized.

@cristianbote

cristianbote Dec 7, 2017

Contributor

Same, fixed in #9

@cristianbote

cristianbote Dec 7, 2017

Contributor

Same, fixed in #9

@kadmil

This comment has been minimized.

Show comment
Hide comment
@kadmil

kadmil Dec 7, 2017

Contributor

Love this api, as you could skip storing your subscriber lambda in separate variable

Contributor

kadmil commented Dec 7, 2017

Love this api, as you could skip storing your subscriber lambda in separate variable

@developit

This comment has been minimized.

Show comment
Hide comment
@developit

developit Dec 7, 2017

Owner

The currently implementation relies on this, which I'd prefer to avoid. Can we either declare store = {} in the createStore() scope, hoist unsubscribe() as an inner function there, or inline unsubscribe() into the returned anonymous function?

Owner

developit commented Dec 7, 2017

The currently implementation relies on this, which I'd prefer to avoid. Can we either declare store = {} in the createStore() scope, hoist unsubscribe() as an inner function there, or inline unsubscribe() into the returned anonymous function?

@cristianbote

This comment has been minimized.

Show comment
Hide comment
@cristianbote

cristianbote Dec 7, 2017

Contributor

Yup. Initially that was my thinking, just inline the unsubscribe and maybe remove it from the api. But, didn't want to introduce breaking changes on day two 😀.

I'll update it, soon.

Contributor

cristianbote commented Dec 7, 2017

Yup. Initially that was my thinking, just inline the unsubscribe and maybe remove it from the api. But, didn't want to introduce breaking changes on day two 😀.

I'll update it, soon.

developit added a commit that referenced this pull request Dec 7, 2017

@developit developit merged commit 3658f4a into developit:master Dec 7, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment