0.1.6 • Published 2 years ago
@hypersphere/omnibus v0.1.6
Hypersphere Omnibus
Installation
yarn add @hypersphere/omnibusFeatures
- Fully typed custom Event Bus
- Each event can be individually typed
- Full code completion
- Levarages TypeScript native functionality (no magic)
- Fully open sourced
Usage
Basic Example
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);Using BusBuilder
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) => { })Using Bus Builder derive
TODO: finish this
Using with using syntax
TODO: finish this
Changelog
Version 0.1.4
- Adding
.oncemethod allowing you to listen to specific event once.
Version 0.1.3
- Added new
.frommethod forOmnibus.builder()- you can now combine events from other buses (including native buses and other libraries!)
Version 0.1.2
- minor: improving returned types by flattening them = better TS inspection
- exposing two new helper types:
OmnibusEventsandOmnibusEventPayload - Fixed issue with Registrator's
.offmethod not working properly - Added support for disposing
OmnibusRegistratorand added documentation around this logic
Version 0.1.1
- Fixing issue with
.reduceinterface - now handles arrays properly - Adding
.memoizebuilder method so values can be properly handled between calls - Fixed bunch of typings
Version 0.1.0
This version is jam-packed with great new features:
- Introducing new
BusBuilderthat allows you to build your event bus in declarative way BusBuilderallows you to compose new events based on the other ones providing powerful way of filtering, mapping and reducing messages- The
onmethod can be now used with new Explicit Resource Management allowing you to useusingkeyword to remove event when exiting function - Breaking change: Removed
functionshelpers as they are now being replaced withBusBuilderapproach
Version 0.0.6
- Fixing issue with delay using interval instead of timeout function.
Version 0.0.5
- Fixed deployment issues.
Version 0.0.4
- Fixed way package was exporting it's functions
- Exporting sourcemaps
Version 0.0.3
- Added
@hypersphere/omnibus/functionsmodule that provides useful helper functionality: delayallows you to get event delayed but set amount of millisecondsskipDuplicatesensures that you won't get 2 same events with the same parameters in a rowfilterprovides generic way for filtering events by providing custom functionthrottleanddebounceprovides functionality of throttling and debouncing events respectively
Version 0.0.2
- Exporting
CallbackTypeandUnregisterCallback - Fixed type of
OmnibusRegistrator - Added
offAllmethod toOmnibusclass. - Added default generic type for
OmnibusandOmnibusRegistrator
Version 0.0.1
- Initial Release