Coder Social home page Coder Social logo

behnammodi / jetemit Goto Github PK

View Code? Open in Web Editor NEW
46.0 6.0 6.0 630 KB

jetemit is an event manager for React, React Native, Vue, Angular, and all javascript project

Home Page: https://npmjs.com/package/jetemit

License: MIT License

JavaScript 100.00%
javascript events listener react

jetemit's Introduction

NPM

Version Minzipped size Downloads License

An event manager very simple

Compatibility

All browser Backend (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

jetemit's People

Contributors

201flaviosilva avatar behnammodi avatar dependabot[bot] avatar mrsoftware avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

jetemit's Issues

How to use in react js

Hi.
I want to use in a reactjs app .
Briefly I emitted an event in a component and subscribed for it in another component constructor but
it does not receive anything .
Something special needs to work?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.