yarn add @hypersphere/omnibus
- Fully typed custom Event Bus
- Each event can be individually typed
- Full code completion
- Levarages TypeScript native functionality (no magic)
- Fully open sourced
import { User, Message } from "./types";
import { Omnibus } from "@hypersphere/omnibus";
interface EventDefinitions {
"message": [message: Message, author: User, recipient: User],
"activity-change": [newActivity: "active"|"inactive", user: User],
};
const bus = new Omnibus<EventDefinitions>();
bus.on("message", (msg, msgAuthor, msgRecipient) => {
// all parameters are properly typed here.
});
bus.on("activity-change", (activity, user) => {
// all parameters are properly typed here too
});
// TypeScript will also make sure those are provided properly.
bus.trigger("message", new Message("xxx"), user1, user2);
import { BusBuilder, args } from '@hypersphere/omnibus';
const bus = BusBuilder
.init()
.register('message', args<string>())
.register('error', args<string>())
.build()
bus.on('message', (x: string) => { })
bus.on('error', (x: string) => { })
TODO: finish this
TODO: finish this
- Adding
.once
method allowing you to listen to specific event once.
- Added new
.from
method forOmnibus.builder()
- you can now combine events from other buses (including native buses and other libraries!)
- minor: improving returned types by flattening them = better TS inspection
- exposing two new helper types:
OmnibusEvents
andOmnibusEventPayload
- Fixed issue with Registrator's
.off
method not working properly - Added support for disposing
OmnibusRegistrator
and added documentation around this logic
- Fixing issue with
.reduce
interface - now handles arrays properly - Adding
.memoize
builder method so values can be properly handled between calls - Fixed bunch of typings
This version is jam-packed with great new features:
- Introducing new
BusBuilder
that allows you to build your event bus in declarative way -
BusBuilder
allows you to compose new events based on the other ones providing powerful way of filtering, mapping and reducing messages - The
on
method can be now used with new Explicit Resource Management allowing you to useusing
keyword to remove event when exiting function - Breaking change: Removed
functions
helpers as they are now being replaced withBusBuilder
approach
- Fixing issue with delay using interval instead of timeout function.
- Fixed deployment issues.
- Fixed way package was exporting it's functions
- Exporting sourcemaps
- Added
@hypersphere/omnibus/functions
module that provides useful helper functionality: -
delay
allows you to get event delayed but set amount of milliseconds -
skipDuplicates
ensures that you won't get 2 same events with the same parameters in a row -
filter
provides generic way for filtering events by providing custom function -
throttle
anddebounce
provides functionality of throttling and debouncing events respectively
- Exporting
CallbackType
andUnregisterCallback
- Fixed type of
OmnibusRegistrator
- Added
offAll
method toOmnibus
class. - Added default generic type for
Omnibus
andOmnibusRegistrator
- Initial Release