proxy-trigger

2.0.4 • Public • Published

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

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
2.0.40latest

Version History

VersionDownloads (Last 7 Days)Published
2.0.40
2.0.30
2.0.20
2.0.10
2.0.00
1.0.00
0.3.00
0.2.00
0.1.00

Package Sidebar

Install

npm i proxy-trigger

Weekly Downloads

0

Version

2.0.4

License

MIT

Unpacked Size

7.76 kB

Total Files

4

Last publish

Collaborators

  • layflags