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

A single observer

  • 0.4.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Easy Observer

Observe a simple property change and trigger listener.

Build Status

Install

npm install easy-observer

Usage

Watch property which is simple value;

import { observeValue } from 'easy-observer';

let a = { name: 'Hello' };

observeValue(a, 'name', (previous, current) => console.log(`${previous} -> ${current}`));

a.name = 'World'; // => Hello -> World;

Watch function;

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

npm install 

npm test

Keywords

FAQs

Package last updated on 25 Jun 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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