Skip to content

Method for syncing emitters #3

Closed

Description

@ryanve

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.

Activity

  1. ryanve commented on May 3, 2014

    @ryanve
    OwnerAuthor

    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?

  2. added 2 commits that reference this issue on May 3, 2014
  3. ryanve commented on May 3, 2014

    @ryanve
    OwnerAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions