All Projects β†’ denosaurs β†’ event

denosaurs / event

Licence: MIT license
πŸ“† Strictly typed event emitter with asynciterator support

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to event

tiny-typed-emitter
Fully type-checked NodeJS EventEmitter
Stars: ✭ 96 (+220%)
Mutual labels:  events, event-emitter
event-emitter
Event Emitter module for Nest framework (node.js) πŸ¦‹
Stars: ✭ 102 (+240%)
Mutual labels:  events, event-emitter
tsee
Typed EventEmitter implemented with tsargs
Stars: ✭ 22 (-26.67%)
Mutual labels:  events, event-emitter
node-await-event-emitter
await events library like EventEmitter
Stars: ✭ 19 (-36.67%)
Mutual labels:  events, event-emitter
spa-bus
πŸ”₯Tools for multilevel components to pass values in any SPA
Stars: ✭ 15 (-50%)
Mutual labels:  events, event-emitter
events
Tiny type-safe event emitter
Stars: ✭ 25 (-16.67%)
Mutual labels:  events, event-emitter
telephone-ts
Telephone-ts: The "Event Emitter-less" TypeScript Event Architecture.
Stars: ✭ 22 (-26.67%)
Mutual labels:  events, event-emitter
micro-typed-events
The smallest, most convenient typesafe TS event emitter you'll ever need
Stars: ✭ 39 (+30%)
Mutual labels:  events, event-emitter
EventEmitter
Simple EventEmitter with multiple listeners
Stars: ✭ 19 (-36.67%)
Mutual labels:  events, event-emitter
i18next-http-backend
i18next-http-backend is a backend layer for i18next using in Node.js, in the browser and for Deno.
Stars: ✭ 270 (+800%)
Mutual labels:  deno
from-event
🦊 ViewChild and FromEvent β€” a Match Made in Angular Heaven
Stars: ✭ 130 (+333.33%)
Mutual labels:  events
niue
A tiny shared state and event library for React
Stars: ✭ 17 (-43.33%)
Mutual labels:  events
deno-task-runner
Task runner for deno
Stars: ✭ 31 (+3.33%)
Mutual labels:  deno
pg-pubsub
Reliable PostgreSQL LISTEN/NOTIFY with inter-process lock support
Stars: ✭ 50 (+66.67%)
Mutual labels:  events
erc20-balance
πŸ’Ž Get 2000+ ERC-20 token balances with JavaScript. Supports Node.js and Deno
Stars: ✭ 18 (-40%)
Mutual labels:  deno
eventcatalog
Discover, Explore and Document your Event Driven Architectures powered by Markdown.
Stars: ✭ 392 (+1206.67%)
Mutual labels:  events
hackertab.dev
Hackertab turns your New Tab page into a geeky one that keeps you as a developer updated with the best tools, news, jobs and events.
Stars: ✭ 229 (+663.33%)
Mutual labels:  events
espresso
Minimal web framework for Deno
Stars: ✭ 43 (+43.33%)
Mutual labels:  deno
denoffi
Deno Foreign Function Interface.
Stars: ✭ 37 (+23.33%)
Mutual labels:  deno
cyberevents
The protocol for EVENTs and TICKETs
Stars: ✭ 16 (-46.67%)
Mutual labels:  events

event

Tags CI Status Dependencies License

Strictly typed event emitter with asynciterator support.

Events should be defined as a literal object type where the key is the event name, and the value is a tuple with any amount of elements of any type.

The constructor takes an optional argument which defines the maximum amount of listeners per event, which defaults to 10. If this limit is surpassed, an error is thrown.


⚠️ Events must be a type, and can't be an interface due to their design differences.


type Events = {
  foo: [string];
  bar: [number, boolean];
};

class MyClass extends EventEmitter<Events> {}
const MyClassInstance = new MyClass();

function listener(num, bool) {}

// add a listener to the bar event
MyClassInstance.on("bar", listener);

// remove a listener from the bar event
MyClassInstance.off("bar", listener);

// remove all listeners from the bar event
MyClassInstance.off("bar");

// remove all listeners from the event emitter
MyClassInstance.off();

// add a one-time listener to the bar event
MyClassInstance.once("bar", listener);

// on, once, and off are chainable
MyClassInstance.on("bar", listener).off("bar", listener);

// emit the bar event with the wanted data
MyClassInstance.emit("bar", 42, true);

// listen to all events with an async iterator
for await (const event of MyClassInstance) {
  if (event.name === "bar") {
    // event.value is of type [number, boolean]
  }
}

// listen to a specific event with an async iterator
for await (const [num, bool] of MyClassInstance.on("bar")) {
}

// removes all listeners and closes async iterators
MyClassInstance.close("bar");

Maintainers

Other

Contribution

Pull request, issues and feedback are very welcome. Code style is formatted with deno fmt and commit messages are done following Conventional Commits spec.

Licence

Copyright 2020-present, the denosaurs team. All rights reserved. MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].