proxy-trigger
v2.0.4
Published
Proxies events from one emitter to another.
Downloads
1
Maintainers
Readme
proxy-trigger
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