Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/behnammodi/jetemit
jetemit is an event manager for React, React Native, Vue, Angular, and all javascript project
https://github.com/behnammodi/jetemit
events javascript listener react
Last synced: 20 days ago
JSON representation
jetemit is an event manager for React, React Native, Vue, Angular, and all javascript project
- Host: GitHub
- URL: https://github.com/behnammodi/jetemit
- Owner: behnammodi
- License: mit
- Created: 2018-09-23T14:44:44.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-07T05:12:20.000Z (almost 2 years ago)
- Last Synced: 2024-05-21T15:33:16.884Z (6 months ago)
- Topics: events, javascript, listener, react
- Language: JavaScript
- Homepage: https://npmjs.com/package/jetemit
- Size: 615 KB
- Stars: 46
- Watchers: 6
- Forks: 6
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![NPM](https://nodei.co/npm/jetemit.png)](https://nodei.co/npm/jetemit/)
An event manager very simple
## Compatibility
| All browser | Backend (Nodejs) | Mobile (React Native) |
| ----------- | ---------------- | --------------------- |
| ✅ | ✅ | ✅ |Compatibility with all javascript project
## Install
```npm
npm install jetemit
```## Import
```javascript
const { on, emit } = require("jetemit");
//or
import { on, emit } from "jetemit";
```# Use
## Call
```javascript
import { emit } from "jetemit";/**
* emit(name, value);
* name is string
* value any
*/
emit("TIME", "2018-12-01 12:30");
```## Listener
```javascript
import { on } from "jetemit";/**
* on(name,function)
* name is string
*/
on("TIME", time => {
console.log(time);
});
``````javascript
import { once } from "jetemit";/**
* Like on but run one time
*/
once("TIME", time => {
console.log(time);
});
```## Unsubscribe listener
```javascript
import { on } from "jetemit";/**
* on return unsubscribe function
*/
const unsubscribe = on("TIME", time => {
console.log(time);
});unsubscribe();
```## Using unsubscribeOf function
```javascript
import { unsubscribeOf } from "jetemit";/**
* Unsubscribe all subscribed functions for TIME
*/
unsubscribeOf("TIME");
```## or
```javascript
/**
* Unsubscribe a Function which subscribed for TIME
*/
unsubscribeOf("TIME", timeFunction);
```## Refund from all listener
Please see this sample:
```javascript
// file a.js
import { on } from "jetemit";on("CACHE_STSTEM_HEALTH", () => {
return { state: "OK", id: "CACHE_SYSTEM_1" };
});
```
```javascript
// file b.jd
import { on } from "jetemit";on("CACHE_STSTEM_HEALTH", () => {
return { state: "OK", id: "CACHE_SYSTEM_2" };
});
```
```javascript
// 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`