Giter Club home page Giter Club logo

spark's Introduction

Spark

Another JavaScript event emitter cause we do not have enough.

I really did not have a particular reason for creating this event emitter. I guess the only 'advantage' this emitter has

npm i @andre_garvin/spark --save

This is same as event emitter for the 'events' module in node

const spark = require('@andre_garvin/spark')
const emitter = new spark()


emitter.on('message', msg => {
    console.log(msg)
})

emitter.once('crash', err => {
    console.error(err)
})

emitter.emit('message', 'Hello, World!')

emitter.emit('crash', 'There is a error')

on: receives the messages being emitted.

emitter.on('event-name', data => console.log)

emit: emits a message or messages to a given event name. You can also pass in multiple arguments be sent to the subscriber of the event that it is being emitted.

emitter.emit('event-name', 'event')
emitter.emit('event-name', [1,2,'bar'], { msg: 'hello, wolrd' }, true, foo(), 17329)

slince: Turns off a event from receiving messages.

// This will do no more harm to anyone anymore
emitter.silence('@channel')

once: Same a the on method but will only receive the emitted message once.
all: Receives messages from specified event names.

// Pass a array of the event names
emitter.all(['hello', 'foo', 'bar'], msg => {
    console.log(msg)
})

// or you can pass in '*' to get all events
emitter.all('*', msg => {
    foo(msg)
})

To see further examples view the test I set up, I believe sometimes it can be very helpful to understand most projects is by reading the test if the documentation is not up to pare.

Contributing:

Hell the why not ? If I make missing spelling or grammar mistakes go a head send a PR on my mistakes.

spark's People

Contributors

andregarvin avatar

Watchers

 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.