Skip to content

mudenglong/hxc3-subscriber

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

subscriber and publish 发布与订阅模式

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published