0.3.8 • Published 2 years ago

levent v0.3.8

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

🚌 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!🧑‍💻

0.3.8

2 years ago

0.3.7

2 years ago

0.3.6

2 years ago

0.3.0

2 years ago

0.2.1

2 years ago

0.1.1

2 years ago