1.0.7 • Published 3 months ago

@chocolatemilkdev/emitter v1.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

@chocolatemilkdev/emitter

a basic event emitter.

Image Image

Features

  • Builded on ESM, CJS and UMD.
  • Type-Safe.
  • Optimized.
  • Basic Usage.

Note:

  • ES6/ES2015 or newer required.

1.0.1

  • bug fix

Usage

import ChocolateMilkEmitter from "@chocolatemilkdev/emitter";//ESM and TS
/**
 * const ChocolateMilkEmitter = require("@chocolatemilkdev/emitter").default
*/
const emitter = new ChocolateMilkEmitter()

emitter.on("a", (number) => {
    console.log(number)
})
emitter.once("b", (str) => {
    console.log(str)
})
emitter.onceAsync("b").then(([bool]) => {
    console.log(bool)
})

emitter.emit("a", 1)
emitter.emit("b", "b")
emitter.emit("c", true)

emitter.hasListener("a", (number) => {
    console.log(number)
})//true
emitter.isEmitted("a")//true

Note: Typing Events

interface MyEvents{
    eat(food: string): any;
    drink(drink: string): string;
}

const emitter = new ChocolateMilkEmitter<MyEvents>()

emitter.on("eat", (food) => {
    console.log(food)
})
emitter.on("drink", (drink) => {
    return "a"
})

emitter.emit("eat", "kebap")//undefined
emitter.emit("drink", "water")//"a"

Contact/Support

Discord

1.0.7

3 months ago

1.0.6

3 months ago

1.0.5

3 months ago

1.0.4

3 months ago

1.0.3

4 months ago

1.0.2

5 months ago

1.0.1

6 months ago

1.0.0

6 months ago