# static-observable

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

Latest version **1.0.5** (published 2020-03-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install static-observable
pnpm add static-observable
yarn add static-observable
bun add static-observable
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2020-03-22 |
| First published | 2016-07-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 12.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Tejesh Mehta |
| Maintainers | tjmehta |
| Keywords | observable, static, methods, next, error, complete, completed, onNext, onError, immediate |

## Links

- npm: https://www.npmjs.com/package/static-observable
- Repository: https://github.com/tjmehta/static-observable
- Homepage: https://github.com/tjmehta/static-observable#readme
- Issues: https://github.com/tjmehta/static-observable/issues
- npm.io page: https://npm.io/package/static-observable

## Alternatives

- [@sentry/react-native](https://npm.io/package/@sentry/react-native.md) — 2.6M weekly downloads
- [@ardatan/aggregate-error](https://npm.io/package/@ardatan/aggregate-error.md) — 708.1K weekly downloads
- [custom-error-generator](https://npm.io/package/custom-error-generator.md) — 2.0K weekly downloads
- [@technik-sde/prosemirror-recreate-transform](https://npm.io/package/@technik-sde/prosemirror-recreate-transform.md) — 1.5K weekly downloads
- [@suchipi/error-utils](https://npm.io/package/@suchipi/error-utils.md) — 78 weekly downloads

## Recent versions

- 1.0.5 (latest) — 2020-03-22
- 1.0.4 — 2020-03-22
- 1.0.3 — 2020-03-22
- 1.0.2 — 2020-03-22
- 1.0.1 — 2017-01-11
- 1.0.0 — 2016-07-22

## README

# static-observable  [![Build Status](https://travis-ci.org/tjmehta/static-observable.svg?branch=master)](https://travis-ci.org/tjmehta/static-observable) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/)
Static observable methods `next`, `error`, and `complete`. Equivalent to `Promise.resolve()` and `Promise.reject()` for promises.

# Installation
```bash
npm i --save static-observable
npm i --save rxjs # peer dependency
```

# Why?
For quick return cases and test stubs

# Usage
Example: chain
```js
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
```js
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"
```js
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

---
_Source: https://npm.io/package/static-observable · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
