@mooyu/fire
v1.0.1
Published
a tool via publish the subscription mode
Downloads
12
Readme
@mooyu/fire
a tool via publish the subscription mode
Usage
npm install @mooyu/fire -D
yarn add @mooyu/fire --dev
// then
import fire from '@mooyu/fire'
API
- fire.on
// Subscribers subscribe to an event, which can be emit by priority
fire.on(evtName: string, cb: Function, priority: number = Infinity)
- fire.once
// only emit once
fire.once(evtName: string, cb: Function, priority: number = Infinity)
- fire.emit
// A publishing method that triggers a subscribed event.
//The argument can be a string or an array of strings, or it can be passed without arguments(emit all). data is a message that is pushed to the subscriber.
// The function accepts an array as the return value as a message that the subscriber feeds back to the publisher. Two-way communication
fire.emit(evtName?: string | Array<string>, data?: any) : Array
- fire.off
// cacel the subscribtion
fire.off(evtName: string| Array<string>, fn?: Function)
- fire.destory
// clear all
fire.destory()
- fire.curr
// return all the data in cache object
fire.curr()