static-observable
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

static-observable Build Status js-standard-style

Static observable methods next, error, and complete. Equivalent to Promise.resolve() and Promise.reject() for promises.

Installation

npm i --save static-observable
npm i --save rxjs # peer dependency 

Why?

For quick return cases and test stubs

Usage

Example: chain

var StaticObservable = require('static-observable')
 
var observable = StaticObservable
  .next({ foo: 1 })
  .next({ foo: 2 })
  .complete()
 
observable.subscribe(
  function (next) { console.log('NEXT:', next )},
  function (err) { console.log('ERROR:', err )},
  function () { console.log('COMPLETE' )}
)
// NEXT: { foo: 1 }
// NEXT: { foo: 2 }
// COMPLETE

Example: error chain

var StaticObservable = require('static-observable')
 
var observable = StaticObservable
  .next({ foo: 1 })
  .next({ foo: 2 })
  .error(new Error('boom'))
 
observable.subscribe(
  function (next) { console.log('NEXT:', next )},
  function (err) { console.log('ERROR:', err )},
  function () { console.log('COMPLETE' )}
)
// NEXT: { foo: 1 }
// NEXT: { foo: 2 }
// ERROR: [Error: boom]

Example: error and complete are "safe"

var StaticObservable = require('static-observable')
 
var observable = StaticObservable
  .error(new Error('boom'))
  .next({ foo: 1 })
 
observable.subscribe(
  function (next) { console.log('NEXT:', next )},
  function (err) { console.log('ERROR:', err )},
  function () { console.log('COMPLETE' )}
)
// ERROR: [Error: boom]
 
var observable = StaticObservable
  .complete(new Error('boom'))
  .next({ foo: 1 })
 
observable.subscribe(
  function (next) { console.log('NEXT:', next )},
  function (err) { console.log('ERROR:', err )},
  function () { console.log('COMPLETE' )}
)
// COMPLETE

License

MIT

Package Sidebar

Install

npm i static-observable

Weekly Downloads

8

Version

1.0.5

License

MIT

Unpacked Size

13 kB

Total Files

9

Last publish

Collaborators

  • tjmehta