hxc3-subscriber

1.0.7 • Public • Published

hxc3-subscriber

订阅与发布

NPM version build status Test coverage gemnasium deps node version npm download

Install

hxc3-subscriber

Usage

subscribe and publish

// 可以直接引用 dist/subscriber.js 获得 EventTarge
// or 使用 import EventTarge from "hxc3-subscriber";
 
var a = new EventTarge();
 
 
// 发布与订阅
// subscribe
a.on('getTodayData', function(data){ ...  });
 
// publish
a.trigger('getTodayData', 'hello world');

support one level namespace(支持一层命名空间)

// 支持一层 命名空间
a.on('getTodayData.abc', function(data){ ...  }); 
a.on('getTodayData.cdef', function(data){ ...  }); 
 
a.trigger('getTodayData', data);
 
// 不支持多层命名空间 not support 
a.on('getTodayData.cdef.child', function(data){ ...  }); 

解绑方式

// Example 1 - off with a token
var token = EventTarget.on('mytopic', myFunc);
PubSub.off(token);
 
// Example 2 - off with only namespace
PubSub.off('.anamespace');
 
// Example 3 - off a topic
PubSub.off('mytopic');
 
// Example 4 - off a topic with namespace
PubSub.off('mytopic.anamespace');

Readme

Keywords

Package Sidebar

Install

npm i hxc3-subscriber

Weekly Downloads

2

Version

1.0.7

License

MIT

Unpacked Size

23.3 kB

Total Files

7

Last publish

Collaborators

  • hhroot