levent
TypeScript icon, indicating that this package has built-in type declarations

0.3.8 • Public • Published

🚌 Levent

A better solution of distributing events in TS and JS.
Test Publish

🌟 High performance
🌟 Async supported
🌟 Sticky event
🌟 Preventable
🌟 Lightful (Minified + Gzipped = 1kB)

Getting Started

yarn add levent

Quick Start

import levent from "levent"

//subscribe event
levent.on("test",(arg:string)=>{
    return arg
})

//publish event.
const values = levent.emit("test","I love you.")

console.log(values) // ['I love you.']

Strict event types.

import { Levent } from "levent"

// create your own event bus instance
const bus : Levent<{
    "example-event":[string,number]
}>

//define the handler
function handler(arg:string){
    return arg.length;
}

//subscribe
bus.on("example-event",handler)

// publish event
const values = bus.emit( "example-event","I Love You")

//desubscribe
bus.off("example-event",handler)

Async☘️

bus.on("example-event",async (arg)=>{
    return await someAsyncOperation(arg)
})

// emit event and wait all handler returns.
const values = await bus.emit("example-event",null,{ async:true })

Hooks

eventx.emit("example-event",null,{
    afterEach:(r:any)=>{
        console.log("last handler's result: " + r)
    }
})

Join in development!🏋🏻‍♂️

1. Get the source

git clone https://github.com/zsh2401/levent && cd levent

2. Go

# Download dependencies
yarn
# Build it
yarn build
# Or run unit test
yarn test

All pull requests are welcomed!🧑‍💻

Readme

Keywords

none

Package Sidebar

Install

npm i levent

Weekly Downloads

1

Version

0.3.8

License

MIT

Unpacked Size

60.3 kB

Total Files

73

Last publish

Collaborators

  • zsh2401