# abstract-observable

> Simple typescript abstract class for observer pattern.

Latest version **0.2.5** (published 2018-10-11) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.5 |
| Published | 2018-10-11 |
| First published | 2018-06-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 684.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Danilo C Castro |
| Maintainers | dan2dev |

## Links

- npm: https://www.npmjs.com/package/abstract-observable
- Repository: https://github.com/dan2dev/abstract-observable
- npm.io page: https://npm.io/package/abstract-observable

## Dependencies (2)

- [asap](https://npm.io/package/asap.md) ^2.0.6
- [@types/asap](https://npm.io/package/@types/asap.md) ^2.0.0

## Recent versions

- 0.2.5 (latest) — 2018-10-11
- 0.2.4 — 2018-10-11
- 0.2.3 — 2018-10-11
- 0.2.2 — 2018-10-11
- 0.2.1 — 2018-10-11
- 0.2.0 — 2018-10-11
- 0.1.12 — 2018-06-28
- 0.1.11 — 2018-06-28
- 0.1.10 — 2018-06-28
- 0.1.9 — 2018-06-28
- 0.1.8 — 2018-06-28
- 0.1.7 — 2018-06-27
- 0.1.6 — 2018-06-26
- 0.1.5 — 2018-06-26
- 0.1.4 — 2018-06-26
- … 3 more at https://npm.io/package/abstract-observable/versions

## README

# abstract-observable
Simple typescript abstract class for observer pattern.
## Install
```bash
yarn add abstract-observable
```
or
```bash
npm install --save abstract-observable
```

### 1 - Create an observable class
```ts
export class WantToBeObserved extends Observable {
  public someAction() {
    // do stuff here then notify
    this.notify();
  }
}
const observableInstance = new WantToBeObserved();
```
### 2 - Create some observers
```ts
export class WantToObserve implements IObserver {
  public notify(): void {
    // do stuff here
  }
}
export function wantToObserveFunction(): void {
  // do some other stuff here
}
```
### 3 - Subscribe the observers
```ts
// subscribe class instance
const observerInstance = new WantToObserve();
const unsubscribeInstance = observableInstance.subscribe(observerInstance);

// subscribe function
observableInstance.subscribe(wantToObserveFunction);

// to unsubscribe call the return of subscribe
unsubscribeInstance();
```

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