From a2f72fe94c8a8a4cbd43cc71b29a99c0c8c195e4 Mon Sep 17 00:00:00 2001 From: William Troup Date: Fri, 5 Jan 2024 22:08:25 +0000 Subject: [PATCH 1/6] Updated project description. --- README.md | 2 +- README_NUGET.md | 2 +- observe.js.nuspec | 2 +- package.json | 2 +- src/observe.js | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 380810b..04370ef 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Observe.js [![coded by William Troup](https://img.shields.io/badge/coded_by-William_Troup-yellow)](https://github.com/williamtroup) ->

A lightweight, and easy-to-use, JavaScript library for observing any kind of JS object, or HTML DOM element, to detect changes!

+>

A lightweight JavaScript library that allows developers to keep track of changes to JavaScript objects and/or DOM elements.

>

v0.5.0



diff --git a/README_NUGET.md b/README_NUGET.md index 74b83df..4dd2d8f 100644 --- a/README_NUGET.md +++ b/README_NUGET.md @@ -7,7 +7,7 @@ [![discussions Welcome](https://img.shields.io/badge/discussions-Welcome-red)](https://github.com/williamtroup/Observe.js/discussions) [![coded by William Troup](https://img.shields.io/badge/coded_by-William_Troup-yellow)](https://github.com/williamtroup) -> A lightweight, and easy-to-use, JavaScript library for observing any kind of JS object, or HTML DOM element, to detect changes! +> A lightweight JavaScript library that allows developers to keep track of changes to JavaScript objects and/or DOM elements. ## What features does Observe.js have? diff --git a/observe.js.nuspec b/observe.js.nuspec index 9fcacab..acf570a 100644 --- a/observe.js.nuspec +++ b/observe.js.nuspec @@ -4,7 +4,7 @@ jObserve.js 0.5.0 Observe.js - A lightweight, and easy-to-use, JavaScript library for observing any kind of JS object, or HTML DOM element, to detect changes. + A lightweight JavaScript library that allows developers to keep track of changes to JavaScript objects and/or DOM elements. William Troup https://github.com/williamtroup/Observe.js diff --git a/package.json b/package.json index 854a4e6..a75f457 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "jobserve.js", "title": "Observe.js", - "description": "A lightweight, and easy-to-use, JavaScript library for observing any kind of JS object, or HTML DOM element, to detect changes.", + "description": "A lightweight JavaScript library that allows developers to keep track of changes to JavaScript objects and/or DOM elements.", "version": "0.5.0", "main": "dist/observe.js", "author": { diff --git a/src/observe.js b/src/observe.js index 8f26e20..7b13f18 100644 --- a/src/observe.js +++ b/src/observe.js @@ -1,7 +1,7 @@ /** * Observe.js * - * A lightweight, and easy-to-use, JavaScript library for observing any kind of JS object, or HTML DOM element, to detect changes. + * A lightweight JavaScript library that allows developers to keep track of changes to JavaScript objects and/or DOM elements. * * @file observe.js * @version v0.5.0 From 46eea4d9c1690cfc8415321f543407cdd89cc214 Mon Sep 17 00:00:00 2001 From: William Troup Date: Fri, 5 Jan 2024 22:09:55 +0000 Subject: [PATCH 2/6] Updated to v0.5.1. --- README.md | 6 +++--- README_NUGET.md | 6 +++--- dist/observe.js | 4 ++-- dist/observe.min.js | 4 ++-- docs/CHANGE_LOG.md | 6 ++++++ observe.js.nuspec | 2 +- package.json | 2 +- src/observe.js | 4 ++-- 8 files changed, 20 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 04370ef..6a1c5e0 100644 --- a/README.md +++ b/README.md @@ -2,15 +2,15 @@ Observe.js [![Tweet](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?text=Observe.js%2C%20a%20free%20JavaScript%observe%builder&url=https://github.com/williamtroup/Observe.js&hashtags=javascript,html,observe) -[![npm](https://img.shields.io/badge/npmjs-v0.5.0-blue)](https://www.npmjs.com/package/jobserve.js) -[![nuget](https://img.shields.io/badge/nuget-v0.5.0-purple)](https://www.nuget.org/packages/jObserve.js/) +[![npm](https://img.shields.io/badge/npmjs-v0.5.1-blue)](https://www.npmjs.com/package/jobserve.js) +[![nuget](https://img.shields.io/badge/nuget-v0.5.1-purple)](https://www.nuget.org/packages/jObserve.js/) [![license](https://img.shields.io/badge/license-MIT-green)](https://github.com/williamtroup/Observe.js/blob/main/LICENSE.txt) [![discussions Welcome](https://img.shields.io/badge/discussions-Welcome-red)](https://github.com/williamtroup/Observe.js/discussions) [![coded by William Troup](https://img.shields.io/badge/coded_by-William_Troup-yellow)](https://github.com/williamtroup) >

A lightweight JavaScript library that allows developers to keep track of changes to JavaScript objects and/or DOM elements.

->

v0.5.0

+>

v0.5.1



diff --git a/README_NUGET.md b/README_NUGET.md index 4dd2d8f..f1f88c4 100644 --- a/README_NUGET.md +++ b/README_NUGET.md @@ -1,8 +1,8 @@ -# Observe.js v0.5.0 +# Observe.js v0.5.1 [![Tweet](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?text=Observe.js%2C%20a%20free%20JavaScript%observe%builder&url=https://github.com/williamtroup/Observe.js&hashtags=javascript,html,observe) -[![npm](https://img.shields.io/badge/npmjs-v0.5.0-blue)](https://www.npmjs.com/package/jobserve.js) -[![nuget](https://img.shields.io/badge/nuget-v0.5.0-purple)](https://www.nuget.org/packages/jObserve.js/) +[![npm](https://img.shields.io/badge/npmjs-v0.5.1-blue)](https://www.npmjs.com/package/jobserve.js) +[![nuget](https://img.shields.io/badge/nuget-v0.5.1-purple)](https://www.nuget.org/packages/jObserve.js/) [![license](https://img.shields.io/badge/license-MIT-green)](https://github.com/williamtroup/Observe.js/blob/main/LICENSE.txt) [![discussions Welcome](https://img.shields.io/badge/discussions-Welcome-red)](https://github.com/williamtroup/Observe.js/discussions) [![coded by William Troup](https://img.shields.io/badge/coded_by-William_Troup-yellow)](https://github.com/williamtroup) diff --git a/dist/observe.js b/dist/observe.js index f3cf285..2a1f732 100644 --- a/dist/observe.js +++ b/dist/observe.js @@ -1,4 +1,4 @@ -/*! Observe.js v0.5.0 | (c) Bunoon | MIT License */ +/*! Observe.js v0.5.1 | (c) Bunoon | MIT License */ (function() { function collectDOMObjects() { var tagTypes = _configuration.domElementTypes; @@ -402,7 +402,7 @@ return this; }; this.getVersion = function() { - return "0.5.0"; + return "0.5.1"; }; (function(documentObject, windowObject) { _parameter_Document = documentObject; diff --git a/dist/observe.min.js b/dist/observe.min.js index 6849f08..9f13310 100644 --- a/dist/observe.min.js +++ b/dist/observe.min.js @@ -1,4 +1,4 @@ -/*! Observe.js v0.5.0 | (c) Bunoon | MIT License */ +/*! Observe.js v0.5.1 | (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],g=n(e.domElementId), p=null;g&&(p=y.getElementById(e.domElementId),r(p)?e.originalObject=p.outerHTML:(e.originalObject=B.empty,u(e.options.onRemove,e.domElementId)));var v=e.cachedObject,m=e.originalObject;m=g?m:JSON.stringify(m);if(v!==m){e.options.reset?g?p.outerHTML=e.cachedObject:e.originalObject=z(v).result:e.cachedObject=m;if(g)u(e.options.onChange,v,m);else if(g=z(v).result,p=z(m).result,!w(g)&&!w(p)){if(w(e.options.propertyNames))for(v=e.options.propertyNames.length,m=0;mb;b++) 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{n(a)&&(c=JSON.parse(a))}catch(f){try{c=eval("("+a+")"),C(c)&&(c=c())}catch(h){b=Q("Errors in object: "+f.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=["*"];n(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)&&n(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)&&n(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 f in d)if(d.hasOwnProperty(f)&&n(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)&&n(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.5.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 +function(){I();return this};this.setConfiguration=function(a){q=t(a)?a:{};P();return this};this.getVersion=function(){return"0.5.1"};(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 aec1aeb..2c7be71 100644 --- a/docs/CHANGE_LOG.md +++ b/docs/CHANGE_LOG.md @@ -1,5 +1,11 @@ # Observe.js - Change Log: +## Version 0.5.1: +- Project description update. + +
+ + ## Version 0.5.0: #### **New Features:** diff --git a/observe.js.nuspec b/observe.js.nuspec index acf570a..772b0f9 100644 --- a/observe.js.nuspec +++ b/observe.js.nuspec @@ -2,7 +2,7 @@ jObserve.js - 0.5.0 + 0.5.1 Observe.js A lightweight JavaScript library that allows developers to keep track of changes to JavaScript objects and/or DOM elements. William Troup diff --git a/package.json b/package.json index a75f457..ffee6bc 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "jobserve.js", "title": "Observe.js", "description": "A lightweight JavaScript library that allows developers to keep track of changes to JavaScript objects and/or DOM elements.", - "version": "0.5.0", + "version": "0.5.1", "main": "dist/observe.js", "author": { "name": "Bunoon" diff --git a/src/observe.js b/src/observe.js index 7b13f18..ab95b8d 100644 --- a/src/observe.js +++ b/src/observe.js @@ -4,7 +4,7 @@ * A lightweight JavaScript library that allows developers to keep track of changes to JavaScript objects and/or DOM elements. * * @file observe.js - * @version v0.5.0 + * @version v0.5.1 * @author Bunoon * @license MIT License * @copyright Bunoon 2023 @@ -717,7 +717,7 @@ * @returns {string} The version number. */ this.getVersion = function() { - return "0.5.0"; + return "0.5.1"; }; From 6d009b1574609acf64eaa1f10d313211303774c0 Mon Sep 17 00:00:00 2001 From: William Troup Date: Fri, 5 Jan 2024 22:11:59 +0000 Subject: [PATCH 3/6] Minor documentation updates. --- README.md | 2 +- README_NUGET.md | 2 +- docs/CHANGE_LOG.md | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6a1c5e0..9943d02 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Observe.js - Zero-dependencies and extremely lightweight! - JS Object and HTML DOM Element watching! - Watch for specific property changes! -- Cancellation and Pausing support! +- Cancel, Pause, and Resume support! - Full API available via public functions. - Fully configurable! - Fully configurable per watch! diff --git a/README_NUGET.md b/README_NUGET.md index f1f88c4..8122dc4 100644 --- a/README_NUGET.md +++ b/README_NUGET.md @@ -15,7 +15,7 @@ - Zero-dependencies and extremely lightweight! - JS Object and HTML DOM Element watching! - Watch for specific property changes! -- Cancellation and Pausing support! +- Cancel, Pause, and Resume support! - Full API available via public functions. - Fully configurable! - Fully configurable per watch! diff --git a/docs/CHANGE_LOG.md b/docs/CHANGE_LOG.md index 2c7be71..7e5bad0 100644 --- a/docs/CHANGE_LOG.md +++ b/docs/CHANGE_LOG.md @@ -2,6 +2,7 @@ ## Version 0.5.1: - Project description update. +- Minor documentation updates.
From 256966fea5ae176bd6fbd9040b5937a435263aed Mon Sep 17 00:00:00 2001 From: William Troup Date: Fri, 5 Jan 2024 22:14:39 +0000 Subject: [PATCH 4/6] Fixed a small fault that prevented the total changes being handled correctly when a watch is stopped. --- dist/observe.js | 2 +- dist/observe.min.js | 2 +- docs/CHANGE_LOG.md | 2 ++ src/observe.js | 4 ++-- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/dist/observe.js b/dist/observe.js index 2a1f732..8c56828 100644 --- a/dist/observe.js +++ b/dist/observe.js @@ -118,13 +118,13 @@ } } } + watch.totalChanges++; if (watch.options.pauseTimeoutOnChange > 0) { pauseWatchObject(storageId, watch.options.pauseTimeoutOnChange); } if (watch.options.cancelOnChange) { cancelWatchObject(storageId); } - watch.totalChanges++; if (watch.options.maximumChangesBeforeCanceling > 0 && watch.totalChanges >= watch.options.maximumChangesBeforeCanceling) { cancelWatchObject(storageId); } diff --git a/dist/observe.min.js b/dist/observe.min.js index 9f13310..d09b11c 100644 --- a/dist/observe.min.js +++ b/dist/observe.min.js @@ -2,7 +2,7 @@ (function(){function I(){for(var a=q.domElementTypes,b=a.length,c=0;c=h.starts){if(d.hasOwnProperty(l)){var e=d[l],g=n(e.domElementId), p=null;g&&(p=y.getElementById(e.domElementId),r(p)?e.originalObject=p.outerHTML:(e.originalObject=B.empty,u(e.options.onRemove,e.domElementId)));var v=e.cachedObject,m=e.originalObject;m=g?m:JSON.stringify(m);if(v!==m){e.options.reset?g?p.outerHTML=e.cachedObject:e.originalObject=z(v).result:e.cachedObject=m;if(g)u(e.options.onChange,v,m);else if(g=z(v).result,p=z(m).result,!w(g)&&!w(p)){if(w(e.options.propertyNames))for(v=e.options.propertyNames.length,m=0;m=e.options.maximumChangesBeforeCanceling&&x(l)}}A(h.expires)&&k>=h.expires&&x(l)}},h.timeout);d[f]=b}return f}function N(a,b,c){var f=c.options,h;for(h in a)if(a.hasOwnProperty(h)){var l=a[h],k=null;b.hasOwnProperty(h)&& +if(g[M]!==p[M]){u(e.options.onChange,g,p);break}}else u(e.options.onChange,g,p);C(e.options.onPropertyChange)&&N(g,p,e)}e.totalChanges++;0=e.options.maximumChangesBeforeCanceling&&x(l)}}A(h.expires)&&k>=h.expires&&x(l)}},h.timeout);d[f]=b}return f}function N(a,b,c){var f=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,f):(!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 n(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, diff --git a/docs/CHANGE_LOG.md b/docs/CHANGE_LOG.md index 7e5bad0..130a2d5 100644 --- a/docs/CHANGE_LOG.md +++ b/docs/CHANGE_LOG.md @@ -3,6 +3,8 @@ ## Version 0.5.1: - Project description update. - Minor documentation updates. +- Fixed a small fault that prevented the total changes being handled correctly when a watch is stopped. +-
diff --git a/src/observe.js b/src/observe.js index ab95b8d..f3640de 100644 --- a/src/observe.js +++ b/src/observe.js @@ -197,6 +197,8 @@ } } + watch.totalChanges++; + if ( watch.options.pauseTimeoutOnChange > 0 ) { pauseWatchObject( storageId, watch.options.pauseTimeoutOnChange ); } @@ -205,8 +207,6 @@ cancelWatchObject( storageId ); } - watch.totalChanges++; - if ( watch.options.maximumChangesBeforeCanceling > 0 && watch.totalChanges >= watch.options.maximumChangesBeforeCanceling ) { cancelWatchObject( storageId ); } From a5c4000cb767a0776d74a4706bebd1783d3482dc Mon Sep 17 00:00:00 2001 From: William Troup Date: Fri, 5 Jan 2024 22:28:55 +0000 Subject: [PATCH 5/6] Added support to watch array objects for changes. --- dist/observe.js | 2 ++ dist/observe.min.js | 20 ++++++++++---------- docs/CHANGE_LOG.md | 2 +- src/observe.js | 3 +++ test/dist/observe.js.basic.html | 10 ++++++++++ test/src/observe.js.basic.html | 10 ++++++++++ 6 files changed, 36 insertions(+), 11 deletions(-) diff --git a/dist/observe.js b/dist/observe.js index 8c56828..1c3c287 100644 --- a/dist/observe.js +++ b/dist/observe.js @@ -116,6 +116,8 @@ if (isDefinedFunction(watch.options.onPropertyChange)) { compareWatchObjectProperties(oldValue, newValue, watch); } + } else { + fireCustomTrigger(watch.options.onChange, oldValue, newValue); } } watch.totalChanges++; diff --git a/dist/observe.min.js b/dist/observe.min.js index d09b11c..44cd370 100644 --- a/dist/observe.min.js +++ b/dist/observe.min.js @@ -1,12 +1,12 @@ /*! Observe.js v0.5.1 | (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],g=n(e.domElementId), -p=null;g&&(p=y.getElementById(e.domElementId),r(p)?e.originalObject=p.outerHTML:(e.originalObject=B.empty,u(e.options.onRemove,e.domElementId)));var v=e.cachedObject,m=e.originalObject;m=g?m:JSON.stringify(m);if(v!==m){e.options.reset?g?p.outerHTML=e.cachedObject:e.originalObject=z(v).result:e.cachedObject=m;if(g)u(e.options.onChange,v,m);else if(g=z(v).result,p=z(m).result,!w(g)&&!w(p)){if(w(e.options.propertyNames))for(v=e.options.propertyNames.length,m=0;m=e.options.maximumChangesBeforeCanceling&&x(l)}}A(h.expires)&&k>=h.expires&&x(l)}},h.timeout);d[f]=b}return f}function N(a,b,c){var f=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,f):(!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 n(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{n(a)&&(c=JSON.parse(a))}catch(f){try{c=eval("("+a+")"),C(c)&&(c=c())}catch(h){b=Q("Errors in object: "+f.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=["*"];n(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)&&n(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)&&n(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 f in d)if(d.hasOwnProperty(f)&&n(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)&&n(d[c].domElementId)&&d[c].domElementId===a){d[c].options.starts=null;b=!0;break}return b};this.searchDomForNewWatches= +(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)? +(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= function(){I();return this};this.setConfiguration=function(a){q=t(a)?a:{};P();return this};this.getVersion=function(){return"0.5.1"};(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 130a2d5..af89466 100644 --- a/docs/CHANGE_LOG.md +++ b/docs/CHANGE_LOG.md @@ -4,7 +4,7 @@ - Project description update. - Minor documentation updates. - Fixed a small fault that prevented the total changes being handled correctly when a watch is stopped. -- +- Added support to watch array objects for changes.
diff --git a/src/observe.js b/src/observe.js index f3640de..6d1a3c3 100644 --- a/src/observe.js +++ b/src/observe.js @@ -194,6 +194,9 @@ if ( isDefinedFunction( watch.options.onPropertyChange ) ) { compareWatchObjectProperties( oldValue, newValue, watch ); } + + } else { + fireCustomTrigger( watch.options.onChange, oldValue, newValue ); } } diff --git a/test/dist/observe.js.basic.html b/test/dist/observe.js.basic.html index ff53f86..cc29493 100644 --- a/test/dist/observe.js.basic.html +++ b/test/dist/observe.js.basic.html @@ -62,6 +62,8 @@

Change Object Values:


+ +

@@ -86,6 +88,8 @@

Additional Data:

window.observeObject.num = 1; window.observeObject.str = "This is a string"; + window.observeArray = [ 1, 2, 3, 4 ]; + function watchNewObject() { watchId = $observe.watch( window.observeObject, { onChange: onObservableObjectChange, @@ -93,6 +97,12 @@

Additional Data:

onCancel: onCancelWatch, propertyNames: [ "bool", "num" ] } ); + + $observe.watch( window.observeArray, { + onChange: onObservableObjectChange, + onPropertyChange: onObservableObjectPropertyChange, + onCancel: onCancelWatch, + } ); } function setupConfiguration() { diff --git a/test/src/observe.js.basic.html b/test/src/observe.js.basic.html index 676ab98..2a73d72 100644 --- a/test/src/observe.js.basic.html +++ b/test/src/observe.js.basic.html @@ -62,6 +62,8 @@

Change Object Values:


+ +

@@ -86,6 +88,8 @@

Additional Data:

window.observeObject.num = 1; window.observeObject.str = "This is a string"; + window.observeArray = [ 1, 2, 3, 4 ]; + function watchNewObject() { watchId = $observe.watch( window.observeObject, { onChange: onObservableObjectChange, @@ -93,6 +97,12 @@

Additional Data:

onCancel: onCancelWatch, propertyNames: [ "bool", "num" ] } ); + + $observe.watch( window.observeArray, { + onChange: onObservableObjectChange, + onPropertyChange: onObservableObjectPropertyChange, + onCancel: onCancelWatch, + } ); } function setupConfiguration() { From 92e174cc074bb82ac75d2366af4f27cf7ec11e2d Mon Sep 17 00:00:00 2001 From: William Troup Date: Fri, 5 Jan 2024 22:29:54 +0000 Subject: [PATCH 6/6] Updated change log. --- docs/CHANGE_LOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/CHANGE_LOG.md b/docs/CHANGE_LOG.md index af89466..0762dc0 100644 --- a/docs/CHANGE_LOG.md +++ b/docs/CHANGE_LOG.md @@ -3,7 +3,7 @@ ## Version 0.5.1: - Project description update. - Minor documentation updates. -- Fixed a small fault that prevented the total changes being handled correctly when a watch is stopped. +- Fixed a small fault that prevented the total changes from being handled correctly when a watch was stopped. - Added support to watch array objects for changes.