observabvue
observable view of observer pattern
Last updated 3 years ago by andy*() .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install observabvue 
SYNC missed versions from official npm registry.

observabvue

vanilla JavaScript implementation of Observer pattern.

Examples

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:

import { Observer, Subject } from 'observabvue';
// or
const { Observer, Subject } = require('observabvue');

Current Tags

  • 0.1.1                                ...           latest (3 years ago)

3 Versions

  • 0.1.1                                ...           3 years ago
  • 0.1.0                                ...           3 years ago
  • 0.0.1                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |