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

typed-rx-emitter

v1.2.0

Published

Typesafe Rx-based emitter

Downloads

18

Readme

Build Status npm mit ts flow

Highlights

  • 100% typesafe:
    • Statically enforces that channels in .on() are defined
    • Statically enforces that channels in .emit() are defined
    • Statically enforces that emitters are called with the correct data given their Message name
    • Statically enforces that listeners are called with the correct data given their Message name
  • Supports all RxJS Observable methods
  • Supports RxJS versions 4, 5, and 6
  • Preforms dynamic analysis to detect and warn about cycles in emitters
  • 3.7kb gzipped & minified (using RxJS6), including RxJS

Installation (with RxJS v5.x or v6.x - recommended)

# Using Yarn:
yarn add typed-rx-emitter rxjs

# Using NPM:
npm install typed-rx-emitter rxjs --save

Installation (with RxJS v4.x)

# Using Yarn:
yarn add typed-rx-emitter@^0.3

# Using NPM:
npm install typed-rx-emitter@^0.3 --save

Usage

import { Emitter } from 'typed-rx-emitter'

// Enumerate messages
type Messages = {
  INCREMENT_COUNTER: number
  OPEN_MODAL: boolean
}

const emitter = new Emitter<Messages>()

// Listen on an event (basic)
emitter
  .on('OPEN_MODAL')
  .subscribe(_ => console.log(`Change modal visibility: ${_}`)) // _ is a boolean

// Listen on an event (advanced)
import { debounceTime, filter } from 'rxjs/operators'

emitter
  .on('INCREMENT_COUNTER')
  .pipe(
    filter(_ => _ > 3), // _ is a number
    debounceTime(100)
  )
  .subscribe(_ => console.log(`Counter incremented to ${_}`)) // _ is a number

// Listen on all events
emitter
  .all()
  .subscribe(() => console.log('Something changed'))

// Trigger an event - throws a compile time error unless id and value are set, and are of the right types
emitter.emit('OPEN_MODAL', true)

// Event is misspelled - throws a compile time error
emitter.emit('INCREMENT_CONTER')

See a complete browser usage example here.

Options

Emitter takes an optional options argument. options is an object, and each key in the object is optional:

| Option | Default | Description | |-|-|-| | Error | CyclicalDependencyError | Custom Error subclass for cycle warning | | isDevMode | false | Perform dynamic analysis to warn about cycles? |

Tests

npm test