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

on-change

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

on-change - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0

36

index.d.ts

@@ -0,1 +1,34 @@

declare namespace onChange {
interface Options {
/**
Deep changes will not trigger the callback. Only changes to the immediate properties of the original object.
@default false
@example
```
import onChange = require('on-change');
const object = {
a: {
b: false
}
};
let i = 0;
const watchedObject = onChange(object, () => {
console.log('Object changed:', ++i);
}, {isShallow: true});
watchedObject.a.b = true;
// Nothing happens
watchedObject.a = true;
//=> 'Object changed: 1'
```
*/
readonly isShallow?: boolean;
}
}
declare const onChange: {

@@ -73,3 +106,4 @@ /**

previousValue: unknown
) => void
) => void,
options?: onChange.Options
): ObjectType;

@@ -76,0 +110,0 @@

4

index.js

@@ -19,3 +19,3 @@ 'use strict';

const onChange = (object, onChange) => {
const onChange = (object, onChange, options = {}) => {
let inApply = false;

@@ -68,3 +68,3 @@ let changed = false;

const value = Reflect.get(target, property, receiver);
if (isPrimitive(value) || property === 'constructor') {
if (isPrimitive(value) || property === 'constructor' || options.isShallow === true) {
return value;

@@ -71,0 +71,0 @@ }

{
"name": "on-change",
"version": "1.2.0",
"version": "1.3.0",
"description": "Watch an object or array for changes",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -78,3 +78,3 @@ # on-change [![Build Status](https://travis-ci.org/sindresorhus/on-change.svg?branch=master)](https://travis-ci.org/sindresorhus/on-change)

### onChange(object, onChange)
### onChange(object, onChange, [options])

@@ -85,3 +85,3 @@ Returns a version of `object` that is watched. It's the exact same object, just with some `Proxy` traps.

Type: `Object`
Type: `object`

@@ -103,3 +103,14 @@ Object to watch for changes.

#### options
Type: `object`
##### isShallow
Type: `boolean`<br>
Default: `false`
Deep changes will not trigger the callback. Only changes to the immediate properties of the original object.
## Use-case

@@ -106,0 +117,0 @@

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