New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

watchwithproxy

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

watchwithproxy

Watch for changes in an object with a proxy

latest
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

WatchWithProxy.ts

This small library, written in Typescript, uses the Proxy object from ecma6 to monitor objects for changes. It then signals a function with the details of the change.

The class itself is fairly simple. It's similar to Watch.js, but written in Typescript, uses Proxies, and doesn't rely on timers to get the addition of new properties. This class is much lighter than Watch.js.

Usage

import * as WatchWithProxy from '../src/';

let options = new WatchWithProxy.WatchOptions();
options.levels = 1;
function listener(sender:any, property: string, oldval:any, newval:any) {
    console.log("Updated callback! sender: ", sender.toString(), "property:", property, "old:", oldval, "new:", newval);
}
let watchedTest3 = WatchWithProxy.Watcher.Watch(test3, options, listener);

After that, all changes to the object watchedtest3 are going to be signaled in the listener function. This module supports arrays and their methods too.

So you can track push, pop, shift, etc...

I may have missed some methods that modify properties. Feel free to add them and send a pull request my way.

The test/index.ts shows a sample showing the various ways to use it.

Keywords

watch

FAQs

Package last updated on 04 Dec 2016

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