New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@suku/typed-rx-emitter

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@suku/typed-rx-emitter

Typesafe Rx-based emitter

  • 1.1.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source
typed-rx-emitter: Typesafe Rx-based event emitter

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
# 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:

OptionDefaultDescription
ErrorCyclicalDependencyErrorCustom Error subclass for cycle warning
isDevModefalsePerform dynamic analysis to warn about cycles?

Tests

npm test

Keywords

FAQs

Package last updated on 13 Nov 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc