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

observable-operators

v1.7.3

Published

A library of Reactive Operators built with ECMAScript Observables from the ground up.

Downloads

28

Readme

ObservableOperators

Build Status Coverage Status npm version

A library of Reactive Operators built with ECMAScript Observables from the ground up.

  • Flexible - Operators can be expressed in functional or fluent format
  • Small - If you want everything there's RxJS, this library has a small set of canonical operators
  • Well documented

Install

Install with npm or yarn:

npm install observable-operators

You will need an ES Observable polyfill. I recommend zen-observable.

Use

This library's default export will add all available methods to the Observable constructor and prototype so that they may be chained in the reactive style:

import addAll from 'observable-operators';

addAll();

Observable.fromEvent(document, 'click')
  .merge(otherClicks)
  .map(parseEvent)
  .filter(theOnesICareAbout)
  .subscribe(console.log);

With require the addAll method can be called inline:

require('observable-operators').addAll();

Observable and Observable.prototype will not be modified unless this function is invoked. If you wish to have all operators available, you should import this module somewhere high-up so that it runs before the rest of your code.

Specifying another target

If you do not wish to modify the global Observable you can pass in a different target object:

addAll(MyObservable)

This will allow chaining on your custom Observable as long as it has the core methods specified in the Observable proposal.

Method types

This library distinguishes between Operators and Creators

  • Operators: Functions that take at least one Observable as input and return something else (either another Observable, a Promise, or other value). All Operators take an Observable as the first argument. This allows them to be used either directly as functions:

    import { map } from 'observable-operators';
    
    map(Observable.of(1, 2, 3), x => x + 1)
      .subscribe(console.log)

    or as chainable methods once the operators are added to Observable.prototype:

    Observable.of(1, 2, 3)
      .map(x => x + 1)
      .merge(otherStream)
      .filter(isOdd)
      .subscribe(console.log)

    The helper method addOperators is used to add operators to Observable.prototype as part of the library's root method. If you wish to cherrypick operators you can do so:

    import { addOperators, filter, merge } from 'observable-operators'
    
    addOperators(Observable.prototype, [filter, merge])
  • Creators: Functions that take other things as inputs and return Observables. Creators may be used directly as functions:

    import { fromEvent } from 'observable-operators'
    
    fromEvent(document, 'click').subscribe(handleEvent)

    or once added to the Observable constructor or another constructor, may be accessed as static methods:

    Observable.fromEvent(document, 'click').subscribe(handleEvent)

    If used as static methods creators will return an instance of the Constructor method to which they are assigned:

    MyObservable.interval(1) instanceof MyObservable // true

    If used directly as a function, a Constructor may be passed in as an optional final argument:

      interval(1000, MyObservable) instanceof MyObservable // true

    By default, creators will return an instance of the global Observable.

    The helper function addCreators is used to add creators to the Observable constructor as part of the library's root method. If you wish to cherrypick creators you may do so:

    import { addCreators, interval, fromEvent } from 'observable-operators'
    
    addCreators(Observable, [interval, fromEvent])

Available Methods

Creators

Operators

Motivation

There are great existing reactive observable libraries out there already such as most.js and RxJS, but none of them that are built from the bottom up on top of the ECMAScript Observable proposal that will (hopefully) be part of the language. This is that library.