page-bus

share an event emitter among pages and frames on the same domain

  • Owner: substack/page-bus
  • Platform:
  • License:: Other
  • Category::
  • Topic:
  • Like:
    0
      Compare:

Github stars Tracking Chart

page-bus

share an event emitter among pages and frames on the same domain

This module works offline and does not rely on any network IO.

Behind the scenes, the localStorage API and the window 'storage' event is used to synchronize
cross-page events.

Previously this module used a shared worker, but shared workers need to elect a
master for the URL.createObjectURL() api which got very complicated.

example

Just create a bus, which returns an event emitter:

var createBus = require('page-bus');
var bus = createBus();

bus.on('hello', function (msg) {
    console.log('msg=', msg);
});

bus.emit('hello', Date.now());

Compile with browserify then open this page up on a few tabs.

The messages get shared hooray!

Check out the demo on neocities.

methods

var createBus = require('page-bus')

var bus = createBus(opts)

Create a new event emitter bus.

  • opts.key - the string key to save data. default: 'page-bus'. By using a
    different value, you can create namespaces.

All other pages on the same domain in the same browser will be able to open the
event emitter.

install

With npm do:

npm install page-bus

license

MIT

Main metrics

Overview
Name With Ownersubstack/page-bus
Primary LanguageJavaScript
Program languageJavaScript (Language Count: 2)
Platform
License:Other
所有者活动
Created At2014-11-13 05:23:36
Pushed At2015-07-07 11:41:54
Last Commit At2015-07-07 04:43:27
Release Count9
Last Release Name3.0.1 (Posted on 2015-07-07 04:43:27)
First Release Name1.0.0 (Posted on 2014-11-12 21:21:10)
用户参与
Stargazers Count156
Watchers Count5
Fork Count6
Commits Count28
Has Issues Enabled
Issues Count2
Issue Open Count2
Pull Requests Count1
Pull Requests Open Count0
Pull Requests Close Count0
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private