sati-dispatch

3.3.3 • Public • Published

sati-dispatch

Small, simple and common dispatch create by laidx;

一个小巧,通用的dispatch库,是一个自定义事件调度器,支持on,call,apply,支持命名空间管理。

支持申明式:先调用register注册所有事件,再调用on,call等方式使用。
非严格模式:无需register,引入后调用on的同时注册事件。
通过new Dispatch(options)时,设置options的strict属性(boolean)。

前言

laidx(boom),前端小白菜一枚,纪念下在我入行8个月左右,发布了我的第一个npm包吧 (ゝ∀・)b

目的是解决: 想要使用d3-dispatch,或者vue的eventbus等等类似的事件调度器时,又不需要完整的引入像d3,vue等如此巨大的库。

因此,就自己实现了一个没有任何依赖的小巧的dispatch,一如常用的使用方法通过npm或者浏览器脚本引入。

Installing

If you use npm.For example:

npm install sati-dispatch;

Get start

import * as Dispatch from 'sati-dispatch';

Import Dispatch

const dispatch = new Dispatch();

API

  • [register] - Register events in strict mode

  • [on] - Listent the event and set a callback function.The function will be trigger When event is dispatched

  • [call] - Afferent a eventName(can be namespace) and trigger this event when it has been matched

  • [apply] - just like [call].The only different is the parameter in callback function was array.

  • [remove] - Remove event by name and it will remove the all callback functions in thie namespace.

Package Sidebar

Install

npm i sati-dispatch

Weekly Downloads

0

Version

3.3.3

License

ISC

Unpacked Size

32.3 kB

Total Files

13

Last publish

Collaborators

  • laidx