# obs-store

> `ObservableStore` is a synchronous in-memory store for a single value, that you can subscribe to updates on.

Latest version **4.0.3** (published 2019-08-20) · ISC license · 0 weekly downloads

## Install

```sh
npm install obs-store
pnpm add obs-store
yarn add obs-store
bun add obs-store
```

## 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 | 4.0.3 |
| Published | 2019-08-20 |
| First published | 2017-01-15 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 18.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 30 |
| Maintainers | brunobar79, danfinlay, kumavis, whymarrh |

## Links

- npm: https://www.npmjs.com/package/obs-store
- Repository: https://github.com/MetaMask/obs-store
- Homepage: https://github.com/MetaMask/obs-store#readme
- Issues: https://github.com/MetaMask/obs-store/issues
- npm.io page: https://npm.io/package/obs-store

## Dependencies (4)

- [xtend](https://npm.io/package/xtend.md) ^4.0.1
- [through2](https://npm.io/package/through2.md) ^2.0.3
- [readable-stream](https://npm.io/package/readable-stream.md) ^2.2.2
- [safe-event-emitter](https://npm.io/package/safe-event-emitter.md) ^1.0.1

## Recent versions

- 4.0.3 (latest) — 2019-08-20
- 4.0.2 — 2019-03-11
- 4.0.1 — 2019-03-11
- 4.0.0 — 2019-03-11
- 3.0.2 — 2018-09-07
- 3.0.1 — 2018-09-07
- 3.0.0 — 2017-11-28
- 2.4.1 — 2017-05-31
- 2.4.0 — 2017-05-31
- 2.3.2 — 2017-02-07
- 2.3.1 — 2017-02-03
- 2.3.0 — 2017-01-29
- 2.2.3 — 2017-01-25
- 2.2.2 — 2017-01-25
- 2.2.1 — 2017-01-25
- … 5 more at https://npm.io/package/obs-store/versions

## README

# ObservableStore

`ObservableStore` is a synchronous in-memory store for a single value,
that you can subscribe to updates on.

```js
const store = new ObservableStore(initState)
store.subscribe(function showValue(value) {
  console.log('saw value:', value)
})

store.putState(5) // "saw value: 5"
store.putState(true) // "saw value: true"
store.putState({ hello: 'world' }) // "saw value: { hello: 'world' }"

console.log(store.getState().hello) // "world"
```

### streams

Each `ObservableStore` can be turned into an `ObservableStoreStream`.
An `ObservableStoreStream` is a duplex stream that you can pipe new values into it or
pipe its updated values out of it.

Special behavior: Doesnt buffer outgoing updates, writes latest state to dest on pipe.

```js
const pipe = require('pump')
const asStream = require('obs-store/lib/asStream')

const storeOne = new ObservableStore(initState)
const storeTwo = new ObservableStore()

pipe(
  asStream(storeOne),
  transformStream,
  asStream(storeTwo)
)
```

### Changelog

##### 3.0.0

`ObservableStore` are no longer streams. You can create streams via `asStream`.

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