easy-observer
Advanced tools
Comparing version 0.2.0 to 0.3.0
{ | ||
"name": "easy-observer", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "A single observer", | ||
"main": "dist/index.js", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "mocha --compilers js:babel-register", | ||
"build": "babel libs -d dist" | ||
"test": "mocha --compilers js:babel-register" | ||
}, | ||
@@ -27,2 +26,4 @@ "keywords": [ | ||
"babel-cli": "^6.10.1", | ||
"babel-plugin-transform-class-properties": "^6.24.1", | ||
"babel-plugin-transform-function-bind": "^6.22.0", | ||
"babel-preset-es2015": "^6.9.0", | ||
@@ -29,0 +30,0 @@ "babel-register": "^6.9.0", |
@@ -5,3 +5,3 @@ ## Easy Observer | ||
[![Build Status](https://travis-ci.org/li-qiang/easy-observer.svg?branch=master)](https://travis-ci.org/li-qiang/easy-observer) | ||
[![Build Status](https://travis-ci.org/fun-coder/easy-observer.svg?branch=master)](https://travis-ci.org/fun-coder/easy-observer) | ||
@@ -16,15 +16,38 @@ ### Install | ||
Watch property which is simple value; | ||
```javascript | ||
import { observe } from 'easy-observer'; | ||
import { observeValue } from 'easy-observer'; | ||
let a = { name: 'Hello' }; | ||
observe(a, 'name', (previous, current) => { | ||
// previous is 'Hello'. | ||
// current is 'World'. | ||
}); | ||
observeValue(a, 'name', (previous, current) => console.log(`${previous} -> ${current}`)); | ||
a.name = 'World'; | ||
a.name = 'World'; // => Hello -> World; | ||
``` | ||
Watch function; | ||
```javascript | ||
import { observeFn, observable } from 'easy-observer'; | ||
const a = observable({ name: 'first', age: 2 }); | ||
const b = observable({ name: 'second' }); | ||
const c = { name: 1 }; | ||
let count = 0; | ||
observeFn(() => { | ||
a.name + b.name + c.name; | ||
count++; | ||
}); // count = 1; Auto run once; | ||
a.name = 'x'; // count = 2; Trigger rerun the function when observed property changed | ||
b.name = 'xx'; // count = 3 | ||
a.age = 3; // count = 3; Not trigger when change the observed property which is not used in the function | ||
c.name = 2; // count = 3; Not trigger when change the non-observed property | ||
``` | ||
### Run Test | ||
@@ -31,0 +54,0 @@ |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
70763
14
58
8
198
1