# vigour-observable

> fast and mem-efficient observables

Latest version **3.1.21** (published 2016-09-26) · ISC license · 0 weekly downloads

## Install

```sh
npm install vigour-observable
pnpm add vigour-observable
yarn add vigour-observable
bun add vigour-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 | 3.1.21 |
| Published | 2016-09-26 |
| First published | 2016-02-23 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | jim de beer |
| Maintainers | jimdebeer, vigour-io |
| Keywords | observable, mem, vigour, base |

## Links

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

## Dependencies (4)

- [bubleify](https://npm.io/package/bubleify.md) 0.5.1
- [vigour-base](https://npm.io/package/vigour-base.md) ^3.3.13
- [vigour-util](https://npm.io/package/vigour-util.md) ^3.0.0
- [vigour-stamp](https://npm.io/package/vigour-stamp.md) ^1.3.4

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads
- [datasets-fi-postalcodes](https://npm.io/package/datasets-fi-postalcodes.md) — 1.1K weekly downloads

## Recent versions

- 3.1.21 (latest) — 2016-09-26
- 3.1.20 — 2016-09-26
- 3.1.19 — 2016-08-28
- 3.1.18 — 2016-08-28
- 3.1.17 — 2016-08-25
- 3.1.16 — 2016-08-25
- 3.1.15 — 2016-08-25
- 3.1.14 — 2016-08-25
- 3.1.13 — 2016-08-24
- 3.1.12 — 2016-07-26
- 3.1.11 — 2016-07-26
- 3.1.10 — 2016-07-25
- 3.1.9 — 2016-07-12
- 3.1.8 — 2016-07-08
- 3.1.7 — 2016-07-03
- … 48 more at https://npm.io/package/vigour-observable/versions

## README

# vigour-observable
[![Build Status](https://travis-ci.org/vigour-io/observable.svg?branch=master)](https://travis-ci.org/vigour-io/observable)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
[![npm version](https://badge.fury.io/js/vigour-observable.svg)](https://badge.fury.io/js/vigour-observable)
[![Coverage Status](https://coveralls.io/repos/github/vigour-io/observable/badge.svg?branch=master)](https://coveralls.io/github/vigour-io/observable?branch=master)

Simple, extendable observables - does not require knowledge of flatmaps, reduce or event streams, inspired by [rx-js](http://reactivex.io/) and modelled as [observ-struct](https://www.npmjs.com/package/observ-struct).

Adds unqiue change stamps see [vigour-stamp](https://github.com/vigour-io/stamp) for more information

Inherits from [vigour-base](https://github.com/vigour-io/base)

####operators and set
```javascript
var Observable = require('vigour-observable')
var name = new Observable({
  val: 'a name',
  $transform (val) {
    return val.toUpperCase()
  }
})

var person = new Observable({ name: 'a name' })

person.name.on(() => {
  // logs "A NAME" when set to the reference
  console.log('hey a name!', person.name.compute())
})

// create an observing reference from person.name to name
person.name.set(name)

// fires the listener on person.name, logs "JAMES"
name.set('james')
```

####on and off
```javascript
var Observable = require('vigour-observable')
var fruits = new Observable()

fruits.on((data, stamp) => {
  // stamp is a unique stamp for each change see vigour-stamp
  // data is the current set obj { banana: 1, kiwi: 1 } in this case
  console.log('fruits!', data, stamp)
})

// this will fire the listener on fruits
fruits.set({ banana: 1, kiwi: 1 })

fruits.banana.once(() => {
  console.log('banana!')
})

// fires banana, does not fire for fruits (by default listeners do not fire for nested fields)
fruits.banana.set(2)

fruits.set({
  // this is the object notation for on listeners - usefull for inheritance
  on: {
    data () {
      // on.data is the default emitter of on
      console.log('any fruit?')
    }
  }
})

// remove the kiwi and fires "any fruit?" and "fruits"
fruits.kiwi.set(null)

// you can make as many emitter types as you want
// will add a listener to the emitter "purchase" with an identifier "history"
fruits.on('purchase', (fruit) => {
  console.log('a purchase!', data)
  this.set({ purchaseHistory: { [fruit]: 1 } })
}, 'history')

fruits.emit('pruchase', 'kiwi')

// remove the listener on purchase with id history
fruits.off('purchase', 'history')

// removes all listeners on purchase
fruits.off('purchase')

// adds the same listener using the object notation
fruits.set({
  on: {
    purchase: {
      history (fruit) {
        this.set({ purchaseHistory: { [fruit]: 1 } })
      }
    }
  }
})
```

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