npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@hypersphere/omnibus

v0.1.6

Published

## Installation ```bash yarn add @hypersphere/omnibus ```

Downloads

2,322

Readme

Hypersphere Omnibus

Installation

yarn add @hypersphere/omnibus

Features

  • 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 .once method allowing you to listen to specific event once.

Version 0.1.3

  • Added new .from method for Omnibus.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: OmnibusEvents and OmnibusEventPayload
  • Fixed issue with Registrator's .off method not working properly
  • Added support for disposing OmnibusRegistrator and added documentation around this logic

Version 0.1.1

  • 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

Version 0.1.0

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 use using keyword to remove event when exiting function
  • Breaking change: Removed functions helpers as they are now being replaced with BusBuilder approach

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/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 and debounce provides functionality of throttling and debouncing events respectively

Version 0.0.2

  • Exporting CallbackType and UnregisterCallback
  • Fixed type of OmnibusRegistrator
  • Added offAll method to Omnibus class.
  • Added default generic type for Omnibus and OmnibusRegistrator

Version 0.0.1

  • Initial Release