# observer-subject

> The subject in the Observer Design Pattern

Latest version **1.1.1** (published 2016-07-10) · ISC license · 0 weekly downloads

## Install

```sh
npm install observer-subject
pnpm add observer-subject
yarn add observer-subject
bun add observer-subject
```

## 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.1.1 |
| Published | 2016-07-10 |
| First published | 2016-07-10 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Lewis Edward Moten III |
| Maintainers | lm3 |
| Keywords | design pattern, observer pattern, observable, software design pattern, subject, dependents, observers, notify, event handling, mvc |

## Links

- npm: https://www.npmjs.com/package/observer-subject
- Repository: https://github.com/lewismoten/observer-subject-js
- Homepage: https://github.com/lewismoten/observer-subject-js#readme
- Issues: https://github.com/lewismoten/observer-subject-js/issues
- npm.io page: https://npm.io/package/observer-subject

## Dependencies (1)

- [is-function](https://npm.io/package/is-function.md) ^1.0.1

## Alternatives

- [async-exit-hook](https://npm.io/package/async-exit-hook.md) — 3.7M weekly downloads
- [evnty](https://npm.io/package/evnty.md) — 7.2K weekly downloads
- [eleventy-plugin-asciidoc](https://npm.io/package/eleventy-plugin-asciidoc.md) — 3.5K weekly downloads
- [@jswork/next-get2get](https://npm.io/package/@jswork/next-get2get.md) — 945 weekly downloads
- [@dashersw/axon](https://npm.io/package/@dashersw/axon.md) — 934 weekly downloads

## Recent versions

- 1.1.1 (latest) — 2016-07-10
- 1.1.0 — 2016-07-10
- 1.0.0 — 2016-07-10

## README

# Observer Design Pattern Subject

An implementation of the subject in an Observer Design Pattern.

## Example

```javascript
let Observable = require('observer-subject'),
  subject = new Observable(),
  observer1 = {
    notify(...args) {

      console.log(`#1`, ...args);

    }

  },
  observer2 = {

    notify(...args) {

      console.log(`#2`, ...args);

    }

  };

subject.registerObserver(observer1);
subject.registerObserver(observer2);
subject.notifyObservers(42);
// #1 42
// #2 42

subject.unregisterObserver(observer1);
subject.notifyObservers(32);
// #2 32
```
## Installation
```
$ npm install observer-subject
```
## API
```javascript
let Observer = require('observer-subject');
```

### .registerObserver(observer)

Will start notifying the observer.

| type | data type | name | Description |
| --- | --- | --- | --- |
| parameter | object | observer | The object to be notified. |
| throws | Type Exception | n/a | Will throw an error if observer does not have a function named `notify`. |

### .unregisterObserver(observer)

Will no longer notify the specified observer.

| type | data type | name | Description |
| --- | --- | --- | --- |
| parameter | object | observer | The object to be notified. |
| returns | boolean | n/a | true if the observer was found and removed, otherwise false |

### .notifyObservers(..args)

Calls each observers `notify` function with the arguments provided.

| type | data type | name | Description |
| --- | --- | --- | --- |
| returns | boolean | n/a | true if game has ended, otherwise false. |

### observer.notify(...args)

Callback that the observable object uses to notify the observer.

| type | data type | name | Description |
| --- | --- | --- | --- |
| parameter | ...* | args | Arguments from the observable object. |

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