GithubHelp home page GithubHelp logo

procot / chnl Goto Github PK

View Code? Open in Web Editor NEW

This project forked from vitalets/chnl

0.0 0.0 0.0 1.42 MB

JavaScript event channels compatible with Chrome extensions API

Home Page: https://vitalets.github.io/chnl

JavaScript 100.00%

chnl's Introduction

chnl

Build Status npm version license

Implementation of event channels (pub/sub, dispatcher, emitter) inspired and compatible with Chrome extensions events API.

Install

npm i chnl --save

Docs

https://vitalets.github.io/chnl

Usage

foo.js

import Channel from 'chnl';

// create channel
export const onData = new Channel();

// subscribe to channel
onData.addListener(data => console.log(data));

bar.js

import {onData} from './foo';

// dispatch event to channel
onData.dispatch({foo: 'bar'});

Adding/removing listeners in dispatching loop

Chnl makes a copy of the listeners before starting dispatching loop. So modifying listeners list (adding/removing) in dispatching loop will affect only the next dispatch:

const onData = new Channel();
const listener1 = () => console.log(1);
const listener2 = () => {
  console.log(2);
  onData.addListener(listener3);
};
const listener3 = () => console.log(3);
onData.addListener(listener1);
onData.addListener(listener2);

onData.dispatch();
// 1
// 2
onData.dispatch();
// 1
// 2
// 3

License

MIT @ Vitaliy Potapov

chnl's People

Contributors

vitalets avatar stamoern avatar

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.