store-event
TypeScript icon, indicating that this package has built-in type declarations

0.0.13 • Public • Published

安装

前往 npm:

$ npm install store-event

状态管理 发布-订阅器 一个基于订阅/发布模式的状态管理器,可用于状态管理,或者事件管理 当作事件管理使用时

// 创建一个管理器
const emitter = new Emitter();
// 监听jump事件
emitter.on('jump', ({ source }) => {
     console.log('触发jump事件', '传入了一个参数source:', source);
}, this);
// 发射事件,并传入参数
emitter.emit('jump', { source: 100 });

当作状态管理使用时

// 创建状态管理器
const store = new Emitter();
// 设置数据
store.data('source', 100);
// 获取数据
console.log(store.data('source'));
// 监听数据变动,第一次就有数据
store.change('source', (data) => {
     cnosole.log('第一次会有数据', data);
}, this);
// 监听数据变动,第一次不会有数据
store.listen('source', (data) => {
     console.log('第一次不会有数据', data);
}, this);
// 改变数据
store.data('source', (data) => {
     return data ++;
});

Package Sidebar

Install

npm i store-event

Weekly Downloads

1

Version

0.0.13

License

MIT

Unpacked Size

17.2 kB

Total Files

6

Last publish

Collaborators

  • hxg2050