1.0.1 • Published 6 years ago

@mooyu/fire v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

@mooyu/fire

styled with prettier Greenkeeper badge Travis Coverage Status

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

  1. fire.on
// Subscribers subscribe to an event, which can be emit by priority
fire.on(evtName: string, cb: Function, priority: number = Infinity)
  1. fire.once
// only emit once
fire.once(evtName: string, cb: Function, priority: number = Infinity)
  1. 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
  1. fire.off
// cacel the subscribtion
fire.off(evtName: string| Array<string>, fn?: Function)
  1. fire.destory
// clear all
fire.destory()
  1. fire.curr
// return all the data in cache object
fire.curr()