https://github.com/andy2046/observabvue
vanilla JavaScript implementation of Observer pattern
https://github.com/andy2046/observabvue
javascript observable observer observer-pattern pattern
Last synced: 9 months ago
JSON representation
vanilla JavaScript implementation of Observer pattern
- Host: GitHub
- URL: https://github.com/andy2046/observabvue
- Owner: andy2046
- License: mit
- Created: 2017-12-18T09:14:29.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-03-14T05:15:04.000Z (almost 8 years ago)
- Last Synced: 2025-02-28T19:12:45.450Z (10 months ago)
- Topics: javascript, observable, observer, observer-pattern, pattern
- Language: JavaScript
- Homepage:
- Size: 129 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# observabvue
vanilla JavaScript implementation of Observer pattern.
## Examples
```js
import { Observer, Subject } from 'observabvue';
const obs1 = Observer.of((data) => {
console.log('obs1', data)
})
const obs2 = Observer.of((data) => {
console.log('obs2', data)
})
const sub1 = Subject.of()
const sub2 = Subject.of()
sub1.registerObserver(obs1)
sub1.registerObserver(obs2)
sub1.notifyObservers()
// obs1 undefined
// obs2 undefined
console.log('sub1', sub1.data)
console.log('sub2', sub2.data)
// sub1 null
// sub2 null
sub1.unregisterObserver(obs1)
sub1.data = {'1': 1}
// obs2 { '1': 1 }
console.log('sub1', sub1.data)
console.log('sub2', sub2.data)
// sub1 { '1': 1 }
// sub2 null
```
## Installation
```
npm install --save observabvue
```
## Usage
You can import from `observabvue`:
```js
import { Observer, Subject } from 'observabvue';
// or
const { Observer, Subject } = require('observabvue');
```