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

Method for syncing emitters #3

Closed
ryanve opened this issue May 3, 2014 · 2 comments
Closed

Method for syncing emitters #3

ryanve opened this issue May 3, 2014 · 2 comments

Comments

@ryanve
Copy link
Owner

ryanve commented May 3, 2014

I've needed several times a convert a function into a emitter like this. I want to add a method to accommodate this. It would allow plain objects or functions to be made emitter-like by receiving properties (and methods) from the source emitter and thus would share listeners with the source.

My original concept was for the method was emitter.into(target) or static energy.into(target) but due to this shared data perhaps emitter.sync(target) or emitter.share(target) is clearer.

ryanve added a commit that referenced this issue May 3, 2014
@ryanve
Copy link
Owner Author

ryanve commented May 3, 2014

When I've used this technique, target has always never been an emitter already. How should that case be handled? Should the source's listeners cache overwrite a target's existing cache?

@ryanve
Copy link
Owner Author

ryanve commented May 3, 2014

I released 0.4.0 with static and instance forms of .to(target) as above.

var f = energy.to(function() {
  f.emit('started')
  // ...
  f.emit('ended')
}).on('ended', function() {
  console.log('ended!')
})

// later
f()

Or use an energy() object:

var f = function() {
  f.emit('called')
}

energy().to(f)
f.on('called', function() {
  console.log('called!')
})

// later
f()

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

No branches or pull requests

1 participant