# with-subscribe

> Minimal Observable interface to watch for object modifications.

Latest version **2.0.0** (published 2018-10-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install with-subscribe
pnpm add with-subscribe
yarn add with-subscribe
bun add with-subscribe
```

## 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 | 2.0.0 |
| Published | 2018-10-04 |
| First published | 2018-04-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 10.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Caio Gondim |
| Maintainers | caiogondim |
| Keywords | observable, subscribe, reactive |

## Links

- npm: https://www.npmjs.com/package/with-subscribe
- npm.io page: https://npm.io/package/with-subscribe

## Dependencies (3)

- [tubo](https://npm.io/package/tubo.md) 1.1.2
- [type-from](https://npm.io/package/type-from.md) 1.0.1
- [symbol-observable](https://npm.io/package/symbol-observable.md) 1.2.0

## Recent versions

- 2.0.0 (latest) — 2018-10-04
- 1.0.1 — 2018-10-04
- 1.0.0 — 2018-04-26

## README

# with-subscribe

<div>
  <img src="https://travis-ci.com/caiogondim/monocle-decorators.js.svg?token=rC867oquXMnLzSZmNcfx&branch=master" alt="Travis CI"> <a href="https://www.npmjs.com/package/with-subscribe"><img src="https://img.shields.io/npm/v/with-subscribe.svg" /></a>
</div>

<br>

Minimal Observable interface to watch for object modifications.

## Installation

```console
npm install --save with-subscribe
```

## Usage

On a constructor:
```js
class Counter {
  constructor() {
    this.count = 0
  }

  increment() {
    this.count += 1
  }
}
const CounterWithSubscribe = withSubscribe(Counter)
const counter = new CounterWithSubscribe()

counter.subscribe(() => console.log('State:', counter.count)) // -> State: 0

counter.increment() // -> State: 1
counter.increment() // -> State: 2
```

As a decorator:
```js
@withSubscribe
class Counter {
  constructor() {
    this.count = 0
  }

  increment() {
    this.count += 1
  }
}
const counter = new Counter()

counter.subscribe(() => console.log('State:', counter.count)) // -> State: 0

counter.increment() // -> State: 1
counter.increment() // -> State: 2
```

On an object:
```js
const counter = withSubscribe({
  count: 0,
  increment() {
    this.count += 1
  }
})

counter.subscribe(() => console.log('State:', counter.count)) // -> State: 0

counter.increment() // -> State: 1
counter.increment() // -> State: 2
```

---

[caiogondim.com](https://caiogondim.com) &nbsp;&middot;&nbsp;
GitHub [@caiogondim](https://github.com/caiogondim) &nbsp;&middot;&nbsp;
Twitter [@caio_gondim](https://twitter.com/caio_gondim)

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