Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
observable-operators
Advanced tools
Readme
A library of Reactive Operators built with ECMAScript Observables from the ground up.
Install with npm
or yarn
:
npm install observable-operators
You will need an ES Observable polyfill. I recommend zen-observable.
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.
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.
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])
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.
FAQs
A library of Reactive Operators built with ECMAScript Observables from the ground up.
The npm package observable-operators receives a total of 2 weekly downloads. As such, observable-operators popularity was classified as not popular.
We found that observable-operators demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.