Comparing version 1.6.1 to 1.6.2
@@ -76,3 +76,2 @@ declare namespace onChange { | ||
@param onChange - Function that gets called anytime the object changes. | ||
@param [options] | ||
@returns A version of `object` that is watched. It's the exact same object, just with some `Proxy` traps. | ||
@@ -146,3 +145,3 @@ | ||
*/ | ||
<ObjectType extends {[key: string]: unknown}>( | ||
<ObjectType extends {[key: string]: any}>( | ||
object: ObjectType, | ||
@@ -167,20 +166,16 @@ onChange: ( | ||
/** | ||
* Returns the original unwatched object. | ||
* | ||
* @param object - Object that is already being watched for changes. | ||
* | ||
* @returns The original unwatched object. | ||
*/ | ||
target(object: object): object; | ||
@param object - Object that is already being watched for changes. | ||
@returns The original unwatched object. | ||
*/ | ||
target<ObjectType extends {[key: string]: any}>(object: ObjectType): ObjectType; | ||
/** | ||
* Cancels all future callbacks on a watched object and returns the original unwatched object. | ||
* | ||
* @param object - Object that is already being watched for changes. | ||
* | ||
* @returns The original unwatched object. | ||
*/ | ||
unsubscribe(object: object): object; | ||
Cancels all future callbacks on a watched object. | ||
@param object - Object that is already being watched for changes. | ||
@returns The original unwatched object. | ||
*/ | ||
unsubscribe<ObjectType extends {[key: string]: any}>(object: ObjectType): ObjectType; | ||
}; | ||
export = onChange; |
25
index.js
@@ -142,2 +142,6 @@ 'use strict'; | ||
const ignoreChange = property => { | ||
return isUnsubscribed || (options.ignoreSymbols === true && typeof property === 'symbol'); | ||
}; | ||
const handler = { | ||
@@ -183,7 +187,7 @@ get(target, property, receiver) { | ||
const ignore = options.ignoreSymbols === true && typeof property === 'symbol'; | ||
const ignore = ignoreChange(property); | ||
const previous = ignore ? null : Reflect.get(target, property, receiver); | ||
const result = Reflect.set(target[proxyTarget] || target, property, value); | ||
if (!isUnsubscribed && !ignore && !equals(previous, value)) { | ||
if (!ignore && !equals(previous, value)) { | ||
handleChange(pathCache.get(target), property, previous, value); | ||
@@ -197,6 +201,9 @@ } | ||
const result = Reflect.defineProperty(target, property, descriptor); | ||
invalidateCachedDescriptor(target, property); | ||
handleChange(pathCache.get(target), property, undefined, descriptor.value); | ||
if (!ignoreChange(property)) { | ||
invalidateCachedDescriptor(target, property); | ||
handleChange(pathCache.get(target), property, undefined, descriptor.value); | ||
} | ||
return result; | ||
@@ -210,8 +217,12 @@ }, | ||
const previous = Reflect.get(target, property); | ||
const ignore = ignoreChange(property); | ||
const previous = ignore ? null : Reflect.get(target, property); | ||
const result = Reflect.deleteProperty(target, property); | ||
invalidateCachedDescriptor(target, property); | ||
handleChange(pathCache.get(target), property, previous); | ||
if (!ignore) { | ||
invalidateCachedDescriptor(target, property); | ||
handleChange(pathCache.get(target), property, previous); | ||
} | ||
return result; | ||
@@ -218,0 +229,0 @@ }, |
{ | ||
"name": "on-change", | ||
"version": "1.6.1", | ||
"version": "1.6.2", | ||
"description": "Watch an object or array for changes", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16090
354