New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

easy-observer

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

easy-observer - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

index.js

9

package.json
{
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc