From cd28ecfcd664bc85cfb3f032e10545d09982bc52 Mon Sep 17 00:00:00 2001 From: William Troup Date: Mon, 8 Jan 2024 11:19:18 +0000 Subject: [PATCH] Minor internal refactoring to make things a little clearer. --- dist/observe.js | 5 ++--- dist/observe.min.js | 18 +++++++++--------- docs/CHANGE_LOG.md | 4 +++- src/observe.js | 6 ++---- 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/dist/observe.js b/dist/observe.js index d106c05..726e28e 100644 --- a/dist/observe.js +++ b/dist/observe.js @@ -149,7 +149,6 @@ } } function compareWatchObjectProperties(oldObject, newObject, watch) { - var options = watch.options; var propertyName; for (propertyName in oldObject) { if (oldObject.hasOwnProperty(propertyName)) { @@ -159,11 +158,11 @@ propertyNewValue = newObject[propertyName]; } if (isDefinedObject(propertyOldValue) && isDefinedObject(propertyNewValue)) { - compareWatchObjectProperties(propertyOldValue, propertyNewValue, options); + compareWatchObjectProperties(propertyOldValue, propertyNewValue, watch.options); } else { if (!isDefinedArray(watch.options.propertyNames) || watch.options.propertyNames.indexOf(propertyName) > -1) { if (JSON.stringify(propertyOldValue) !== JSON.stringify(propertyNewValue)) { - fireCustomTrigger(options.onPropertyChange, propertyName, propertyOldValue, propertyNewValue); + fireCustomTrigger(watch.options.onPropertyChange, propertyName, propertyOldValue, propertyNewValue); } } } diff --git a/dist/observe.min.js b/dist/observe.min.js index 1af929d..3c1b1bf 100644 --- a/dist/observe.min.js +++ b/dist/observe.min.js @@ -1,12 +1,12 @@ /*! Observe.js v0.6.0 | (c) Bunoon | MIT License */ -(function(){function I(){for(var a=q.domElementTypes,b=a.length,c=0;c=h.starts){if(d.hasOwnProperty(l)){var e=d[l],f=p(e.domElementId), -m=null;f&&(m=y.getElementById(e.domElementId),r(m)?e.originalObject=m.outerHTML:(e.originalObject=B.empty,u(e.options.onRemove,e.domElementId)));var v=e.cachedObject,n=e.originalObject;n=f?n:JSON.stringify(n);if(v!==n){e.options.reset?f?m.outerHTML=e.cachedObject:e.originalObject=z(v).result:e.cachedObject=n;if(f)u(e.options.onChange,v,n);else if(f=z(v).result,m=z(n).result,w(f)||w(m))u(e.options.onChange,f,m);else{if(w(e.options.propertyNames))for(v=e.options.propertyNames.length,n=0;n=e.options.maximumChangesBeforeCanceling&&x(l)}}A(h.expires)&&k>=h.expires&&x(l)}},h.timeout);d[g]=b}return g}function N(a,b,c){var g=c.options,h;for(h in a)if(a.hasOwnProperty(h)){var l= -a[h],k=null;b.hasOwnProperty(h)&&(k=b[h]);t(l)&&t(k)?N(l,k,g):(!w(c.options.propertyNames)||-1b;b++){8!==b&&12!==b&&16!==b&&20!==b||a.push("-");var c=Math.floor(16*Math.random()).toString(16);a.push(c)}return a.join(B.empty)}function r(a){return null!==a&&void 0!==a&&a!==B.empty}function t(a){return r(a)&&"object"===typeof a}function p(a){return r(a)&&"string"===typeof a}function C(a){return r(a)&&"function"===typeof a}function w(a){return t(a)&&a instanceof Array}function A(a){return t(a)&& -a instanceof Date}function H(a,b){return r(a)&&"boolean"===typeof a?a:b}function D(a,b){return C(a)?a:b}function G(a,b){return r(a)&&"number"===typeof a?a:b}function z(a){var b=!0,c=null;try{p(a)&&(c=JSON.parse(a))}catch(g){try{c=eval("("+a+")"),C(c)&&(c=c())}catch(h){b=Q("Errors in object: "+g.message+", "+h.message),c=null}}return{parsed:b,result:c}}function Q(a){var b=!0;q.safeMode||(console.error(a),b=!1);return b}function P(){q.safeMode=H(q.safeMode,!0);var a=q,b=q.domElementTypes,c=["*"];p(b)? +(function(){function I(){for(var a=q.domElementTypes,b=a.length,c=0;c=k.starts){if(d.hasOwnProperty(h)){var e=d[h],g=p(e.domElementId), +m=null;g&&(m=y.getElementById(e.domElementId),r(m)?e.originalObject=m.outerHTML:(e.originalObject=B.empty,u(e.options.onRemove,e.domElementId)));var v=e.cachedObject,n=e.originalObject;n=g?n:JSON.stringify(n);if(v!==n){e.options.reset?g?m.outerHTML=e.cachedObject:e.originalObject=z(v).result:e.cachedObject=n;if(g)u(e.options.onChange,v,n);else if(g=z(v).result,m=z(n).result,w(g)||w(m))u(e.options.onChange,g,m);else{if(w(e.options.propertyNames))for(v=e.options.propertyNames.length,n=0;n=e.options.maximumChangesBeforeCanceling&&x(h)}}A(k.expires)&&l>=k.expires&&x(h)}},k.timeout);d[f]=b}return f}function N(a,b,c){for(var f in a)if(a.hasOwnProperty(f)){var k=a[f], +h=null;b.hasOwnProperty(f)&&(h=b[f]);t(k)&&t(h)?N(k,h,c.options):(!w(c.options.propertyNames)||-1b;b++){8!==b&&12!==b&&16!==b&&20!==b||a.push("-");var c=Math.floor(16*Math.random()).toString(16);a.push(c)}return a.join(B.empty)}function r(a){return null!==a&&void 0!==a&&a!==B.empty}function t(a){return r(a)&&"object"===typeof a}function p(a){return r(a)&&"string"===typeof a}function C(a){return r(a)&&"function"===typeof a}function w(a){return t(a)&&a instanceof Array}function A(a){return t(a)&& +a instanceof Date}function H(a,b){return r(a)&&"boolean"===typeof a?a:b}function D(a,b){return C(a)?a:b}function G(a,b){return r(a)&&"number"===typeof a?a:b}function z(a){var b=!0,c=null;try{p(a)&&(c=JSON.parse(a))}catch(f){try{c=eval("("+a+")"),C(c)&&(c=c())}catch(k){b=Q("Errors in object: "+f.message+", "+k.message),c=null}}return{parsed:b,result:c}}function Q(a){var b=!0;q.safeMode||(console.error(a),b=!1);return b}function P(){q.safeMode=H(q.safeMode,!0);var a=q,b=q.domElementTypes,c=["*"];p(b)? (b=b.split(B.space),0===b.length&&(b=c)):b=w(b)?b:c;a.domElementTypes=b}var y=null,E=null,B={empty:""},d={},q={};this.watch=function(a,b){return L(a,b)};this.cancelWatch=function(a){var b=!1;if(d.hasOwnProperty(a))x(a),b=!0;else for(var c in d)if(d.hasOwnProperty(c)&&p(d[c].domElementId)&&d[c].domElementId===a){x(c);b=!0;break}return b};this.cancelWatches=function(){O();return this};this.getWatch=function(a){var b=null;if(d.hasOwnProperty(a))b=d[a];else for(var c in d)if(d.hasOwnProperty(c)&&p(d[c].domElementId)&& -d[c].domElementId===a){b=d[c];break}return b};this.getWatches=function(){return d};this.pauseWatch=function(a,b){var c=!1;if(d.hasOwnProperty(a))c=F(a,b);else for(var g in d)if(d.hasOwnProperty(g)&&p(d[g].domElementId)&&d[g].domElementId===a){c=F(g,b);break}return c};this.resumeWatch=function(a){var b=!1;if(d.hasOwnProperty(a))d[a].options.starts=null,b=!0;else for(var c in d)if(d.hasOwnProperty(c)&&p(d[c].domElementId)&&d[c].domElementId===a){d[c].options.starts=null;b=!0;break}return b};this.searchDomForNewWatches= +d[c].domElementId===a){b=d[c];break}return b};this.getWatches=function(){return d};this.pauseWatch=function(a,b){var c=!1;if(d.hasOwnProperty(a))c=F(a,b);else for(var f in d)if(d.hasOwnProperty(f)&&p(d[f].domElementId)&&d[f].domElementId===a){c=F(f,b);break}return c};this.resumeWatch=function(a){var b=!1;if(d.hasOwnProperty(a))d[a].options.starts=null,b=!0;else for(var c in d)if(d.hasOwnProperty(c)&&p(d[c].domElementId)&&d[c].domElementId===a){d[c].options.starts=null;b=!0;break}return b};this.searchDomForNewWatches= function(){I();return this};this.setConfiguration=function(a){q=t(a)?a:{};P();return this};this.getVersion=function(){return"0.6.0"};(function(a,b){y=a;E=b;P();y.addEventListener("DOMContentLoaded",function(){I()});E.addEventListener("unload",function(){O()});r(E.$observe)||(E.$observe=this)})(document,window)})(); \ No newline at end of file diff --git a/docs/CHANGE_LOG.md b/docs/CHANGE_LOG.md index fb42e7c..bd052ef 100644 --- a/docs/CHANGE_LOG.md +++ b/docs/CHANGE_LOG.md @@ -1,7 +1,9 @@ # Observe.js - Change Log: ## Version 0.6.0: -- + +#### **General Improvements:** +- Minor internal refactoring to make things a little clearer.
diff --git a/src/observe.js b/src/observe.js index 54a2b89..5f4514b 100644 --- a/src/observe.js +++ b/src/observe.js @@ -236,8 +236,6 @@ } function compareWatchObjectProperties( oldObject, newObject, watch ) { - var options = watch.options; - for ( var propertyName in oldObject ) { if ( oldObject.hasOwnProperty( propertyName ) ) { var propertyOldValue = oldObject[ propertyName ], @@ -248,12 +246,12 @@ } if ( isDefinedObject( propertyOldValue ) && isDefinedObject( propertyNewValue ) ) { - compareWatchObjectProperties( propertyOldValue, propertyNewValue, options ); + compareWatchObjectProperties( propertyOldValue, propertyNewValue, watch.options ); } else { if ( !isDefinedArray( watch.options.propertyNames ) || watch.options.propertyNames.indexOf( propertyName ) > -1 ) { if ( JSON.stringify( propertyOldValue ) !== JSON.stringify( propertyNewValue ) ) { - fireCustomTrigger( options.onPropertyChange, propertyName, propertyOldValue, propertyNewValue ); + fireCustomTrigger( watch.options.onPropertyChange, propertyName, propertyOldValue, propertyNewValue ); } } }