Skip to content

Patch 1#13

Open
limitall wants to merge 3 commits intogunn:masterfrom
limitall:patch-1
Open

Patch 1#13
limitall wants to merge 3 commits intogunn:masterfrom
limitall:patch-1

Conversation

@limitall
Copy link

No description provided.

New change for 
1. allow pass arg to subscrib function
2. Now subscribe function will return index of added function
3. add new unSubscribe function
e.g:

import createStore from 'pure-store';
this.setStateState({isLogin:false});
gStore = createStore({
    isLogdin: true
});

gStore.subscribe((setState)=>{
setState({isLogin:gStore.getState().isLogdin})
},this.setState);
@gunn
Copy link
Owner

gunn commented Dec 26, 2018

Hi @limitall,

In the example from your commit comment:

gStore.subscribe((setState)=>{
  setState({isLogin: gStore.getState().isLogdin})
}, this.setState);

Could be written currently as just:

gStore.subscribe(()=> {
  this.setState({isLogin: gStore.state.isLogdin})
});

Also, if you're using pure-store, you usually won't need to use setState as much - just access gStore.state.isLogdin directly. Or perhaps destructure it first - const { isLogdin } = gStore.state.


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 !==

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants