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

@feng3d/watcher

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@feng3d/watcher - npm Package Compare versions

Comparing version 0.5.0 to 0.6.0

18

dist/index.d.ts

@@ -1,13 +0,1 @@

/**
* 观察装饰器,观察被装饰属性的变化
*
* @param onChange 属性变化回调 例如参数为“onChange”时,回调将会调用this.onChange(property, oldValue, newValue)
*
* 使用@watch后会自动生成一个带"_"的属性,例如 属性"a"会生成"_a"
*
* 通过使用 eval 函数 生成出 与自己手动写的set get 一样的函数,性能已经接近 手动写的get set函数。
*
* 性能比Watcher.watch更加高效,但还是建议使用 Watcher.watch 替代 @watch ,由于 @watch 没有对onChange更好的约束 使用 时容易出现运行时报错。
*/
declare function watch(onChange: string): (target: any, property: string) => void;
declare class Watcher {

@@ -21,3 +9,3 @@ /**

* @param property 被监听属性
* @param handler 变化回调函数 (object: T, property: string, oldValue: V) => void
* @param handler 变化回调函数 (newValue: V, oldValue: V, object: T, property: string) => void
* @param thisObject 变化回调函数 this值

@@ -31,3 +19,3 @@ */

* @param property 被监听属性
* @param handler 变化回调函数 (object: T, property: string, oldValue: V) => void
* @param handler 变化回调函数 (newValue: V, oldValue: V, object: T, property: string) => void
* @param thisObject 变化回调函数 this值

@@ -124,3 +112,3 @@ */

export { Watcher, __watchchains__, __watchs__, watch, watcher };
export { Watcher, __watchchains__, __watchs__, watcher };
export as namespace feng3d;
/*!
* @feng3d/watcher - v0.5.0
* Compiled Tue, 26 Jul 2022 03:59:23 UTC
* @feng3d/watcher - v0.6.0
* Compiled Wed, 24 Aug 2022 05:16:18 UTC
*

@@ -12,32 +12,2 @@ * @feng3d/watcher is licensed under the MIT License.

/**
* 观察装饰器,观察被装饰属性的变化
*
* @param onChange 属性变化回调 例如参数为“onChange”时,回调将会调用this.onChange(property, oldValue, newValue)
*
* 使用@watch后会自动生成一个带"_"的属性,例如 属性"a"会生成"_a"
*
* 通过使用 eval 函数 生成出 与自己手动写的set get 一样的函数,性能已经接近 手动写的get set函数。
*
* 性能比Watcher.watch更加高效,但还是建议使用 Watcher.watch 替代 @watch ,由于 @watch 没有对onChange更好的约束 使用 时容易出现运行时报错。
*/
function watch(onChange) {
return function (target, property) {
var key = "_" + property;
console.assert(target[onChange], "\u5728\u5BF9\u8C61 " + target + " \u4E0A\u627E\u4E0D\u5230\u65B9\u6CD5 " + onChange);
Object.defineProperty(target, property, {
get: function () { return this[key]; },
set: function (value) {
if (this[key] === value) {
return;
}
var oldValue = this[key];
this[key] = value;
this[onChange](property, oldValue, value);
},
enumerable: true,
configurable: true,
});
};
}
var Watcher = /** @class */ (function () {

@@ -54,3 +24,3 @@ function Watcher() {

* @param property 被监听属性
* @param handler 变化回调函数 (object: T, property: string, oldValue: V) => void
* @param handler 变化回调函数 (newValue: V, oldValue: V, object: T, property: string) => void
* @param thisObject 变化回调函数 this值

@@ -115,3 +85,3 @@ */

* @param property 被监听属性
* @param handler 变化回调函数 (object: T, property: string, oldValue: V) => void
* @param handler 变化回调函数 (newValue: V, oldValue: V, object: T, property: string) => void
* @param thisObject 变化回调函数 this值

@@ -434,3 +404,2 @@ */

exports.__watchs__ = __watchs__;
exports.watch = watch;
exports.watcher = watcher;

@@ -437,0 +406,0 @@

6

dist/index.min.js
/*!
* @feng3d/watcher - v0.5.0
* Compiled Tue, 26 Jul 2022 03:59:23 UTC
* @feng3d/watcher - v0.6.0
* Compiled Wed, 24 Aug 2022 05:16:18 UTC
*

@@ -8,3 +8,3 @@ * @feng3d/watcher is licensed under the MIT License.

*/
this.feng3d=this.feng3d||{};var _feng3d_watcher=function(t){"use strict";var e=function(){function t(){this._binds=[]}return t.prototype.watch=function(t,e,n,i){Object.getOwnPropertyDescriptor(t,r)||Object.defineProperty(t,r,{value:{},enumerable:!1,configurable:!0,writable:!1});var h=e,o=t[r];if(!o[h]){var s=Object.getOwnPropertyDescriptor(t,h);o[h]={value:t[h],oldPropertyDescriptor:s,handlers:[]};var u=a(t,h);if(u&&u.set&&u.get){var f=(u={enumerable:u.enumerable,configurable:!0,get:u.get,set:u.set}).set;u.set=function(t){var e=this[h];e!==t&&(f&&f.call(this,t),c(t,e,this,h))}}else{if(u&&(u.get||u.set))return void console.warn("watch "+t+" . "+h+" 失败!");(u={enumerable:!0,configurable:!0}).get=function(){return this[r][h].value},u.set=function(t){var e=this[r][h].value;e!==t&&(this[r][h].value=t,c(t,e,this,h))}}Object.defineProperty(t,h,u)}var l=o[h];l.handlers.reduce((function(t,e){return t||e.handler===n&&e.thisObject===i}),!1)||l.handlers.push({handler:n,thisObject:i})},t.prototype.unwatch=function(t,e,n,i){var c=t[r];if(c){var a=e;if(c[a]){var h=c[a].handlers;void 0===n&&(h.length=0);for(var o=h.length-1;o>=0;o--)h[o].handler!==n||h[o].thisObject!==i&&void 0!==i||h.splice(o,1);if(0===h.length){var s=t[a];delete t[a],c[a].oldPropertyDescriptor&&Object.defineProperty(t,a,c[a].oldPropertyDescriptor),t[a]=s,delete c[a]}0===Object.keys(c).length&&delete t[r]}}},t.prototype.bind=function(t,e,n,r){var i=function(){n[r]=t[e]},c=function(){t[e]=n[r]};this.watch(t,e,i),this.watch(n,r,c),this._binds.push([t,e,i,n,r,c])},t.prototype.unbind=function(t,e,n,r){for(var i=this._binds,c=i.length-1;c>=0;c--){var a=i[c];if((a[1]===e&&a[4]===r||a[1]===r&&a[4]===e)&&(a[0]===t&&a[3]===n||a[0]===n&&a[3]===t)){this.unwatch(a[0],a[1],a[2]),this.unwatch(a[3],a[4],a[5]),i.splice(c,1);break}}},t.prototype.watchchain=function(t,e,n,r){var c=this,a=e.indexOf(".");if(-1!==a){Object.getOwnPropertyDescriptor(t,i)||Object.defineProperty(t,i,{value:{},enumerable:!1,writable:!1,configurable:!0});var h=t[i];h[e]||(h[e]=[]);var s=h[e];if(!s.reduce((function(t,e){return t||e.handler===n&&e.thisObject===r}),!1)){var u=e.substr(0,a),f=e.substr(a+1);t[u]&&this.watchchain(t[u],f,n,r);var l=function(t,e){e&&c.unwatchchain(e,f,n,r),t&&c.watchchain(t,f,n,r);var i=o(e,f),a=o(t,f);i!==a&&n.call(r,a,i,t,f)};this.watch(t,u,l),s.push({handler:n,thisObject:r,watchchainFun:l})}}else this.watch(t,e,n,r)},t.prototype.unwatchchain=function(t,e,n,r){var c=e.indexOf(".");if(-1!==c){var a=e.substr(0,c),o=e.substr(c+1),s=t[i];if(s&&s[e]){for(var u=s[e],f=u.length-1;f>=0;f--){var l=u[f];(h(n)||n===l.handler&&r===l.thisObject)&&(t[a]&&this.unwatchchain(t[a],o,l.handler,l.thisObject),this.unwatch(t,a,l.watchchainFun),u.splice(f,1))}0===u.length&&delete s[e],0===Object.keys(s).length&&delete t[i]}}else this.unwatch(t,e,n,r)},t.prototype.watchobject=function(t,e,n,r){var i=this;s(e).forEach((function(e){i.watchchain(t,e,n,r)}))},t.prototype.unwatchobject=function(t,e,n,r){var i=this;s(e).forEach((function(e){i.unwatchchain(t,e,n,r)}))},t}(),n=new e,r="__watchs__",i="__watchchains__";function c(t,e,n,i){n[r][i].handlers.forEach((function(r){r.handler.call(r.thisObject,t,e,n,i)}))}function a(t,e){var n=Object.getOwnPropertyDescriptor(t,e);if(n)return n;var r=Object.getPrototypeOf(t);return r?a(r,e):void 0}function h(t){return null==t}function o(t,e){"string"==typeof e&&(e=e.split("."));for(var n=t,r=0;r<e.length;r++){if(h(n))return;n=n[e[r]]}return n}function s(t){for(var e=[],n=Object.keys(t),r=new Array(n.length).fill(t),i=new Array(n.length).fill(-1),c=0,a=function(){var t=r[c],a=n[c],o=t[a],s=void 0;if(h(o)||function(t){if(null==t||"boolean"==typeof t||"string"==typeof t||"number"==typeof t)return!0;return!1}(o)||0===(s=Object.keys(o)).length){for(var u=[a],f=c;-1!==(f=i[f]);)u.push(n[f]);u.reverse(),e.push(u.join("."))}else s.forEach((function(t){n.push(t),r.push(o),i.push(c)}));c++};c<n.length;)a();return e}return t.Watcher=e,t.__watchchains__=i,t.__watchs__=r,t.watch=function(t){return function(e,n){var r="_"+n;console.assert(e[t],"在对象 "+e+" 上找不到方法 "+t),Object.defineProperty(e,n,{get:function(){return this[r]},set:function(e){if(this[r]!==e){var i=this[r];this[r]=e,this[t](n,i,e)}},enumerable:!0,configurable:!0})}},t.watcher=n,Object.defineProperty(t,"__esModule",{value:!0}),t}({});Object.assign(this.feng3d,_feng3d_watcher);
this.feng3d=this.feng3d||{};var _feng3d_watcher=function(t){"use strict";var e=function(){function t(){this._binds=[]}return t.prototype.watch=function(t,e,n,i){Object.getOwnPropertyDescriptor(t,r)||Object.defineProperty(t,r,{value:{},enumerable:!1,configurable:!0,writable:!1});var h=e,o=t[r];if(!o[h]){var s=Object.getOwnPropertyDescriptor(t,h);o[h]={value:t[h],oldPropertyDescriptor:s,handlers:[]};var u=a(t,h);if(u&&u.set&&u.get){var f=(u={enumerable:u.enumerable,configurable:!0,get:u.get,set:u.set}).set;u.set=function(t){var e=this[h];e!==t&&(f&&f.call(this,t),c(t,e,this,h))}}else{if(u&&(u.get||u.set))return void console.warn("watch "+t+" . "+h+" 失败!");(u={enumerable:!0,configurable:!0}).get=function(){return this[r][h].value},u.set=function(t){var e=this[r][h].value;e!==t&&(this[r][h].value=t,c(t,e,this,h))}}Object.defineProperty(t,h,u)}var l=o[h];l.handlers.reduce((function(t,e){return t||e.handler===n&&e.thisObject===i}),!1)||l.handlers.push({handler:n,thisObject:i})},t.prototype.unwatch=function(t,e,n,i){var c=t[r];if(c){var a=e;if(c[a]){var h=c[a].handlers;void 0===n&&(h.length=0);for(var o=h.length-1;o>=0;o--)h[o].handler!==n||h[o].thisObject!==i&&void 0!==i||h.splice(o,1);if(0===h.length){var s=t[a];delete t[a],c[a].oldPropertyDescriptor&&Object.defineProperty(t,a,c[a].oldPropertyDescriptor),t[a]=s,delete c[a]}0===Object.keys(c).length&&delete t[r]}}},t.prototype.bind=function(t,e,n,r){var i=function(){n[r]=t[e]},c=function(){t[e]=n[r]};this.watch(t,e,i),this.watch(n,r,c),this._binds.push([t,e,i,n,r,c])},t.prototype.unbind=function(t,e,n,r){for(var i=this._binds,c=i.length-1;c>=0;c--){var a=i[c];if((a[1]===e&&a[4]===r||a[1]===r&&a[4]===e)&&(a[0]===t&&a[3]===n||a[0]===n&&a[3]===t)){this.unwatch(a[0],a[1],a[2]),this.unwatch(a[3],a[4],a[5]),i.splice(c,1);break}}},t.prototype.watchchain=function(t,e,n,r){var c=this,a=e.indexOf(".");if(-1!==a){Object.getOwnPropertyDescriptor(t,i)||Object.defineProperty(t,i,{value:{},enumerable:!1,writable:!1,configurable:!0});var h=t[i];h[e]||(h[e]=[]);var s=h[e];if(!s.reduce((function(t,e){return t||e.handler===n&&e.thisObject===r}),!1)){var u=e.substr(0,a),f=e.substr(a+1);t[u]&&this.watchchain(t[u],f,n,r);var l=function(t,e){e&&c.unwatchchain(e,f,n,r),t&&c.watchchain(t,f,n,r);var i=o(e,f),a=o(t,f);i!==a&&n.call(r,a,i,t,f)};this.watch(t,u,l),s.push({handler:n,thisObject:r,watchchainFun:l})}}else this.watch(t,e,n,r)},t.prototype.unwatchchain=function(t,e,n,r){var c=e.indexOf(".");if(-1!==c){var a=e.substr(0,c),o=e.substr(c+1),s=t[i];if(s&&s[e]){for(var u=s[e],f=u.length-1;f>=0;f--){var l=u[f];(h(n)||n===l.handler&&r===l.thisObject)&&(t[a]&&this.unwatchchain(t[a],o,l.handler,l.thisObject),this.unwatch(t,a,l.watchchainFun),u.splice(f,1))}0===u.length&&delete s[e],0===Object.keys(s).length&&delete t[i]}}else this.unwatch(t,e,n,r)},t.prototype.watchobject=function(t,e,n,r){var i=this;s(e).forEach((function(e){i.watchchain(t,e,n,r)}))},t.prototype.unwatchobject=function(t,e,n,r){var i=this;s(e).forEach((function(e){i.unwatchchain(t,e,n,r)}))},t}(),n=new e,r="__watchs__",i="__watchchains__";function c(t,e,n,i){n[r][i].handlers.forEach((function(r){r.handler.call(r.thisObject,t,e,n,i)}))}function a(t,e){var n=Object.getOwnPropertyDescriptor(t,e);if(n)return n;var r=Object.getPrototypeOf(t);return r?a(r,e):void 0}function h(t){return null==t}function o(t,e){"string"==typeof e&&(e=e.split("."));for(var n=t,r=0;r<e.length;r++){if(h(n))return;n=n[e[r]]}return n}function s(t){for(var e=[],n=Object.keys(t),r=new Array(n.length).fill(t),i=new Array(n.length).fill(-1),c=0,a=function(){var t=r[c],a=n[c],o=t[a],s=void 0;if(h(o)||function(t){if(null==t||"boolean"==typeof t||"string"==typeof t||"number"==typeof t)return!0;return!1}(o)||0===(s=Object.keys(o)).length){for(var u=[a],f=c;-1!==(f=i[f]);)u.push(n[f]);u.reverse(),e.push(u.join("."))}else s.forEach((function(t){n.push(t),r.push(o),i.push(c)}));c++};c<n.length;)a();return e}return t.Watcher=e,t.__watchchains__=i,t.__watchs__=r,t.watcher=n,Object.defineProperty(t,"__esModule",{value:!0}),t}({});Object.assign(this.feng3d,_feng3d_watcher);
//# sourceMappingURL=index.min.js.map
/*!
* @feng3d/watcher - v0.5.0
* Compiled Tue, 26 Jul 2022 03:59:23 UTC
* @feng3d/watcher - v0.6.0
* Compiled Wed, 24 Aug 2022 05:16:18 UTC
*

@@ -8,32 +8,2 @@ * @feng3d/watcher is licensed under the MIT License.

*/
/**
* 观察装饰器,观察被装饰属性的变化
*
* @param onChange 属性变化回调 例如参数为“onChange”时,回调将会调用this.onChange(property, oldValue, newValue)
*
* 使用@watch后会自动生成一个带"_"的属性,例如 属性"a"会生成"_a"
*
* 通过使用 eval 函数 生成出 与自己手动写的set get 一样的函数,性能已经接近 手动写的get set函数。
*
* 性能比Watcher.watch更加高效,但还是建议使用 Watcher.watch 替代 @watch ,由于 @watch 没有对onChange更好的约束 使用 时容易出现运行时报错。
*/
function watch(onChange) {
return function (target, property) {
var key = "_" + property;
console.assert(target[onChange], "\u5728\u5BF9\u8C61 " + target + " \u4E0A\u627E\u4E0D\u5230\u65B9\u6CD5 " + onChange);
Object.defineProperty(target, property, {
get: function () { return this[key]; },
set: function (value) {
if (this[key] === value) {
return;
}
var oldValue = this[key];
this[key] = value;
this[onChange](property, oldValue, value);
},
enumerable: true,
configurable: true,
});
};
}
var Watcher = /** @class */ (function () {

@@ -50,3 +20,3 @@ function Watcher() {

* @param property 被监听属性
* @param handler 变化回调函数 (object: T, property: string, oldValue: V) => void
* @param handler 变化回调函数 (newValue: V, oldValue: V, object: T, property: string) => void
* @param thisObject 变化回调函数 this值

@@ -111,3 +81,3 @@ */

* @param property 被监听属性
* @param handler 变化回调函数 (object: T, property: string, oldValue: V) => void
* @param handler 变化回调函数 (newValue: V, oldValue: V, object: T, property: string) => void
* @param thisObject 变化回调函数 this值

@@ -427,3 +397,3 @@ */

export { Watcher, __watchchains__, __watchs__, watch, watcher };
export { Watcher, __watchchains__, __watchs__, watcher };
//# sourceMappingURL=index.es.js.map
/*!
* @feng3d/watcher - v0.5.0
* Compiled Tue, 26 Jul 2022 03:59:23 UTC
* @feng3d/watcher - v0.6.0
* Compiled Wed, 24 Aug 2022 05:16:18 UTC
*

@@ -12,32 +12,2 @@ * @feng3d/watcher is licensed under the MIT License.

/**
* 观察装饰器,观察被装饰属性的变化
*
* @param onChange 属性变化回调 例如参数为“onChange”时,回调将会调用this.onChange(property, oldValue, newValue)
*
* 使用@watch后会自动生成一个带"_"的属性,例如 属性"a"会生成"_a"
*
* 通过使用 eval 函数 生成出 与自己手动写的set get 一样的函数,性能已经接近 手动写的get set函数。
*
* 性能比Watcher.watch更加高效,但还是建议使用 Watcher.watch 替代 @watch ,由于 @watch 没有对onChange更好的约束 使用 时容易出现运行时报错。
*/
function watch(onChange) {
return function (target, property) {
var key = "_" + property;
console.assert(target[onChange], "\u5728\u5BF9\u8C61 " + target + " \u4E0A\u627E\u4E0D\u5230\u65B9\u6CD5 " + onChange);
Object.defineProperty(target, property, {
get: function () { return this[key]; },
set: function (value) {
if (this[key] === value) {
return;
}
var oldValue = this[key];
this[key] = value;
this[onChange](property, oldValue, value);
},
enumerable: true,
configurable: true,
});
};
}
var Watcher = /** @class */ (function () {

@@ -54,3 +24,3 @@ function Watcher() {

* @param property 被监听属性
* @param handler 变化回调函数 (object: T, property: string, oldValue: V) => void
* @param handler 变化回调函数 (newValue: V, oldValue: V, object: T, property: string) => void
* @param thisObject 变化回调函数 this值

@@ -115,3 +85,3 @@ */

* @param property 被监听属性
* @param handler 变化回调函数 (object: T, property: string, oldValue: V) => void
* @param handler 变化回调函数 (newValue: V, oldValue: V, object: T, property: string) => void
* @param thisObject 变化回调函数 this值

@@ -434,4 +404,3 @@ */

exports.__watchs__ = __watchs__;
exports.watch = watch;
exports.watcher = watcher;
//# sourceMappingURL=index.js.map
{
"name": "@feng3d/watcher",
"version": "0.5.0",
"version": "0.6.0",
"description": "对象属性监听器",

@@ -14,4 +14,4 @@ "main": "lib/index.js",

"clean": "rimraf \"{lib,dist}\"",
"build": "npm run clean && rollup -c",
"build:prod": "npm run clean && cross-env NODE_ENV=production rollup -c",
"build": "rollup -c",
"build:prod": "cross-env NODE_ENV=production rollup -c",
"watch": "rollup -cw",

@@ -22,3 +22,3 @@ "test": "mocha",

"docs": "typedoc",
"release":"npm run build:prod && npm publish"
"release": "npm run clean && npm run build:prod && npm publish"
},

@@ -40,2 +40,3 @@ "repository": {

"@types/mocha": "9.1.0",
"@types/node": "^18.6.1",
"@typescript-eslint/eslint-plugin": "5.17.0",

@@ -59,2 +60,3 @@ "@typescript-eslint/parser": "5.17.0",

"ts-node": "10.7.0",
"tslib": "^2.4.0",
"typedoc": "0.21.4",

@@ -61,0 +63,0 @@ "typedoc-plugin-sourcefile-url": "1.0.6",

@@ -1,39 +0,1 @@

/**
* 观察装饰器,观察被装饰属性的变化
*
* @param onChange 属性变化回调 例如参数为“onChange”时,回调将会调用this.onChange(property, oldValue, newValue)
*
* 使用@watch后会自动生成一个带"_"的属性,例如 属性"a"会生成"_a"
*
* 通过使用 eval 函数 生成出 与自己手动写的set get 一样的函数,性能已经接近 手动写的get set函数。
*
* 性能比Watcher.watch更加高效,但还是建议使用 Watcher.watch 替代 @watch ,由于 @watch 没有对onChange更好的约束 使用 时容易出现运行时报错。
*/
export function watch(onChange: string)
{
return (target: any, property: string) =>
{
const key = `_${property}`;
console.assert(target[onChange], `在对象 ${target} 上找不到方法 ${onChange}`);
Object.defineProperty(target, property, {
get() { return this[key]; },
set(value)
{
if (this[key] === value)
{
return;
}
const oldValue = this[key];
this[key] = value;
this[onChange](property, oldValue, value);
},
enumerable: true,
configurable: true,
});
};
}
export class Watcher

@@ -48,3 +10,3 @@ {

* @param property 被监听属性
* @param handler 变化回调函数 (object: T, property: string, oldValue: V) => void
* @param handler 变化回调函数 (newValue: V, oldValue: V, object: T, property: string) => void
* @param thisObject 变化回调函数 this值

@@ -131,3 +93,3 @@ */

* @param property 被监听属性
* @param handler 变化回调函数 (object: T, property: string, oldValue: V) => void
* @param handler 变化回调函数 (newValue: V, oldValue: V, object: T, property: string) => void
* @param thisObject 变化回调函数 this值

@@ -134,0 +96,0 @@ */

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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