browser-eventemitter
v1.0.0
Published
An event emitter for the browser which broadcasts/listens to same-origin iframes
Downloads
4
Maintainers
Readme
Browser Events
This this node event emitter designed to be included in an application which makes use of separate document contexts but allows for a single "event bus" to communicate between these contexts. It uses a MutationObserver
to add contexts to the local list, and when you call emit
, it will use the postMessage
API to propagate these events across the various contexts
ES6 & jsnext:main
This library is written in ES6 making use of it's feature set with reckless abandon. You'll find the source in the src/
directory, and a babelified version under dist/
. The main
key in the package.json points to dist/browser-events.js
, the jsnext:main
key points to the ES6 version. This allows this code to be used with something like rollup.
Class
This module is an ES6 class which extends the EventEmitter object. EGAD A CLASS. Relax. If you have a fundamental disagreement with using the class
keyword in ES6, don't use it. It's pretty simple.
Personally, I'm tired of the anti-pattern of copy/pasting prototype/construction extension/assignment code when I want to do something like this in javascript, and I don't want to include all of util
just to get util.inherits
. Thankfully, if you're so fundamentally opposed you can use the transpiled version under dist/
which does the "appropriate" prototype juggling. If you're still upset about this, just relax. I'll be over here enjoying my new syntax and being lazy and not harming anyone, and you can be right where you, annoyed that someone is using it.
Usage
const BrowserEventEmitter = require('browser-eventemitter')
const emitter = new BrowserEventEmitter()
emitter.on('event', function (msg) {
console.log(msg.some);
})
emitter.emit('event', {some: 'data'})
// data
`
Installation
npm install --save browser-events
Tests
Uses Zuul. Seems like PhantomJS doesn't work anymore on El Capitan.
License
Copyright © 2015 Scripto. Use under the Apache-2.0.