7.0.3 • Published 2 years ago

jetemit v7.0.3

Weekly downloads
118
License
ISC
Repository
github
Last release
2 years ago

NPM

An event manager very simple

Compatibility

All browserBackend (Nodejs)Mobile (React Native)

Compatibility with all javascript project

Install

npm install jetemit

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" }
]
*/

Donate

BTC: 1NV1sjQnXwuyHgxQ8G5eWprhxsD5A8yN6r

7.0.3

2 years ago

7.0.2

3 years ago

7.0.1

3 years ago

7.0.0

3 years ago

6.0.0

3 years ago

5.0.0

4 years ago

4.0.0

5 years ago

3.3.0

5 years ago

3.1.1

5 years ago

3.1.0

5 years ago

3.0.9

5 years ago

3.0.8

5 years ago

3.0.7

5 years ago

3.0.6

5 years ago

3.0.5

5 years ago

3.0.4

5 years ago

3.0.3

5 years ago

3.0.2

5 years ago

3.0.1

5 years ago

3.0.0

5 years ago

2.2.3

5 years ago

2.2.2

6 years ago

2.2.1

6 years ago

2.2.0

6 years ago

2.1.0

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago