jetemit
events manager
Last updated 9 months ago by itten .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install jetemit 
SYNC missed versions from official npm registry.

jetemit

NPM

install size dependencies

Version License Downloads

events manager very simple

Compatibility

All browser Backend (Nodejs) Mobile (React Native)

Compatibility with all javascript project

Install

npm install jetemit --save

Import

const { on, emit } = require("jetemit");
//or
import { on, emit } from "jetemit";

Use

Call

import { emit } from "jetemit";
/**
 * emit(name, value);
 * name is string
 * value any
 */
emit("TIME", "2018-12-01 12:30");

Listener

import { on } from "jetemit";
/**
 * on(name,function)
 * name is string
 */
on("TIME", time => {
  console.log(time);
});
import { once } from "jetemit";
/**
 * Like on but run one time
 */
once("TIME", time => {
  console.log(time);
});

Unsubscribe listener

import { on } from "jetemit";
/**
 * on return unsubscribe function
 */
const unsubscribe = on("TIME", time => {
  console.log(time);
});

unsubscribe();

Using unsubscribeOf function

import { unsubscribeOf } from "jetemit";
/**
 * Unsubscribe all subscribed functions for TIME
 */
unsubscribeOf("TIME");

or

/**
 * Unsubscribe a Function which subscribed for TIME
 */
unsubscribeOf("TIME", timeFunction);

Refund from all listener

Please see this sample:

// file a.js
import { on } from "jetemit";

on("CACHE_STSTEM_HEALTH", () => {
  return { state: "OK", id: "CACHE_SYSTEM_1" };
});

// file b.jd
import { on } from "jetemit";

on("CACHE_STSTEM_HEALTH", () => {
  return { state: "OK", id: "CACHE_SYSTEM_2" };
});

// file c.js
import { on, emit } from "jetemit";

const status = emit("CACHE_STSTEM_HEALTH");
console.log(status);
/*
[
  { state: "OK", id: "CACHE_SYSTEM_1" },
  { state: "OK", id: "CACHE_SYSTEM_2" }
]
*/

Current Tags

  • 5.0.0                                ...           latest (9 months ago)

28 Versions

  • 5.0.0                                ...           9 months ago
  • 4.0.0                                ...           a year ago
  • 3.3.0                                ...           2 years ago
  • 3.1.1                                ...           2 years ago
  • 3.1.0                                ...           2 years ago
  • 3.0.9                                ...           2 years ago
  • 3.0.8                                ...           2 years ago
  • 3.0.7                                ...           2 years ago
  • 3.0.6                                ...           2 years ago
  • 3.0.5                                ...           2 years ago
  • 3.0.4                                ...           2 years ago
  • 3.0.3                                ...           2 years ago
  • 3.0.2                                ...           2 years ago
  • 3.0.1                                ...           2 years ago
  • 3.0.0                                ...           2 years ago
  • 2.2.3                                ...           2 years ago
  • 2.2.2                                ...           2 years ago
  • 2.2.1                                ...           2 years ago
  • 2.2.0                                ...           2 years ago
  • 2.1.0                                ...           2 years ago
  • 2.0.1                                ...           2 years ago
  • 2.0.0                                ...           2 years ago
  • 1.1.1                                ...           2 years ago
  • 1.1.0                                ...           2 years ago
  • 1.0.3                                ...           2 years ago
  • 1.0.2                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 14
Dependencies (0)
None
Dev Dependencies (0)
None

Copyright 2014 - 2017 © taobao.org |