1.0.7 • Published 5 years ago

hxc3-subscriber v1.0.7

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

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');
1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.0.9

7 years ago