Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/andy2046/observabvue
vanilla JavaScript implementation of Observer pattern
https://github.com/andy2046/observabvue
javascript observable observer observer-pattern pattern
Last synced: about 1 month 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 (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-03-14T05:15:04.000Z (almost 7 years ago)
- Last Synced: 2024-11-13T17:54:57.181Z (about 2 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 undefinedconsole.log('sub1', sub1.data)
console.log('sub2', sub2.data)
// sub1 null
// sub2 nullsub1.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');
```