page-bus

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

  • 所有者: substack/page-bus
  • 平台:
  • 许可证: Other
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

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

主要指标

概览
名称与所有者substack/page-bus
主编程语言JavaScript
编程语言JavaScript (语言数: 2)
平台
许可证Other
所有者活动
创建于2014-11-13 05:23:36
推送于2015-07-07 11:41:54
最后一次提交2015-07-07 04:43:27
发布数9
最新版本名称3.0.1 (发布于 2015-07-07 04:43:27)
第一版名称1.0.0 (发布于 2014-11-12 21:21:10)
用户参与
星数156
关注者数5
派生数6
提交数28
已启用问题?
问题数2
打开的问题数2
拉请求数1
打开的拉请求数0
关闭的拉请求数0
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?