Skip to content
Proxies events from one emitter to another.
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
test
.babelrc
.gitignore
LICENSE
README.md
package-lock.json
package.json

README.md

proxy-trigger

es6 js-standard-style CircleCI

Proxies ampersand-events or Backbone.Events from one emitter to another.

A note about compatibility

The npm package should be used in an ES6 environment. Even though the published code has ES5 syntax it uses some ES6 features, so you have to make sure to use ES5 and ES6 polyfills if you are in an ancient environment.

Install

npm install proxy-trigger

Usage

import proxyTrigger from 'proxy-trigger'

// proxy all events by default
proxyTrigger(sourceEmitter, targetEmitter)
targetEmitter.on('foo bar', (msg) => console.log(msg))
sourceEmitter.trigger('foo', 'proxied foo')
sourceEmitter.trigger('bar', 'proxied bar')
// -> proxied foo
// -> proxied bar

// proxy a single event
proxyTrigger(sourceEmitter, targetEmitter, 'change:title')
targetEmitter.on('change:title', () => console.log('title changed'))
sourceEmitter.trigger('change:title')
// -> title changed

// proxy multiple events with a space-separated string
proxyTrigger(sourceEmitter, targetEmitter, 'open close')

// proxy multiple events with an array of strings
proxyTrigger(sourceEmitter, targetEmitter, ['open', 'close'])

// proxy events with name mapping using object notation
proxyTrigger(sourceEmitter, targetEmitter, {'change:title': 'change:source.title'})

// everything mixed
proxyTrigger(sourceEmitter, targetEmitter, [
  'open close', {'change:title': 'change:source.title'}
])

Mixin usage

import {mixin as proxyTriggerMixin} from 'proxy-trigger'
import View from 'ampersand-view'

export default View.extend(proxyTriggerMixin, {
  initialize () {
    this.proxyTrigger(this.someSubView, 'close')
  },
  ...
})

Test

npm test

License

MIT

You can’t perform that action at this time.