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?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?