Socket
Book a DemoInstallSign in
Socket

array-spy

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

array-spy

Patches native JavaScript arrays to be observable.

latest
Source
npmnpm
Version
0.1.0
Version published
Weekly downloads
2
-33.33%
Maintainers
1
Weekly downloads
 
Created
Source

Array Spy

This library provides the means to observe changes to native JavaScript arrays. It does this by patching the core array methods (ie. push) and announcing every time they are called.

Install

Download a UMD bundle from the releases page. The variable arraySpy will be attached to window.

<script type="text/javascript" src="array-spy.js"></script>

If using Browserify or Node.js, you can install via NPM.

$ npm install array-spy

Usage

To use, call the arraySpy() method on any array.

var arraySpy = require("array-spy");
var myarr = [];
arraySpy(myarr);

The array becomes patched, which adds an observe() method to it. Anytime the array is modified via one of the methods, the observe function is called with changes. The changes object will provide an index and the number of added and removed items.

myarr.observe(function(chgs) {
	console.log(chgs);
});

myarr.push("some value");

Keywords

observe

FAQs

Package last updated on 07 Jul 2015

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