Skip to content
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

[Feature] Add EventEmitter namespace support #16

Closed
leeluolee opened this issue Aug 12, 2015 · 0 comments
Closed

[Feature] Add EventEmitter namespace support #16

leeluolee opened this issue Aug 12, 2015 · 0 comments

Comments

@leeluolee
Copy link
Owner

In practice, I found that using stateman as a mediator for passing message among states is a good idea.
For example.

var stateman = stateman();

stateman.state('app.blog', {
    enter: function(){
        stateman.emit('enter-blog')
    }
})
stateman.state('app.user', {
    enter: function(){
        this.handle = function(){console.log('enter the app.blog')}
        stateman.on('enter-blog', this.handle)
    },
    leave: function(){
       stateman.off('enter-blog', this.handle)

    }
})

But , we should kept the reference (this.handle above) for listener, beacuse we will remove it when state is leaving.

So, if we introduced namespace, we can coding like:

stateman.state('app.user', {
    enter: function(){
        stateman.on('user:enter-blog', function(){console.log('app.blog')})
    },
    leave: function(){
       stateman.off('user:enter-blog')
    }
})

Now, we can remove enter-blog event with the namespace user directly without keeping the reference for handle. It won't affect other listener with the same eventType( enter-blog)

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

No branches or pull requests

1 participant