@xuda.io/runtime-bundle 1.0.387 → 1.0.389

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -31983,10 +31983,87 @@ func.UI.screen.execute_xu_functions = async function (SESSION_ID, is_skeleton, $
31983
31983
  // },
31984
31984
  // });
31985
31985
 
31986
- Object.observe(_session.DS_GLB[paramsP.dsSessionP], function (changes) {
31987
- console.log(changes);
31986
+ // Object.observe(_session.DS_GLB[paramsP.dsSessionP], function (changes) {
31987
+ // console.log(changes);
31988
+ // });
31989
+
31990
+ // create a new instance of `MutationObserver` named `observer`,
31991
+ // passing it a callback function
31992
+ // const observer = new MutationObserver(() => {
31993
+ // console.log('callback that runs when observer is triggered');
31994
+ // });
31995
+
31996
+ // // call `observe()`, passing it the element to observe, and the options object
31997
+ // observer.observe(_session.DS_GLB[paramsP.dsSessionP], {
31998
+ // subtree: true,
31999
+ // childList: true,
32000
+ // });
32001
+ //==================
32002
+ class ObjectObserver {
32003
+ constructor(targetObject, callback) {
32004
+ this.callback = callback;
32005
+ this.target = targetObject;
32006
+
32007
+ // Create a proxy to intercept property access and modifications
32008
+ this.proxy = new Proxy(targetObject, {
32009
+ set: (target, property, value) => {
32010
+ const oldValue = target[property];
32011
+ target[property] = value;
32012
+
32013
+ // Call the callback with mutation information
32014
+ this.callback({
32015
+ type: 'update',
32016
+ object: target,
32017
+ property,
32018
+ oldValue,
32019
+ newValue: value,
32020
+ });
32021
+
32022
+ return true;
32023
+ },
32024
+
32025
+ deleteProperty: (target, property) => {
32026
+ const oldValue = target[property];
32027
+ const deleted = delete target[property];
32028
+
32029
+ if (deleted) {
32030
+ this.callback({
32031
+ type: 'delete',
32032
+ object: target,
32033
+ property,
32034
+ oldValue,
32035
+ });
32036
+ }
32037
+
32038
+ return deleted;
32039
+ },
32040
+ });
32041
+
32042
+ return this.proxy;
32043
+ }
32044
+
32045
+ // Method to stop observing (for cleanup)
32046
+ disconnect() {
32047
+ this.callback = null;
32048
+ this.target = null;
32049
+ this.proxy = null;
32050
+ }
32051
+ }
32052
+
32053
+ // Usage example:
32054
+ const originalObject = _session.DS_GLB[paramsP.dsSessionP];
32055
+
32056
+ // Create observer with callback
32057
+ const observedObject = new ObjectObserver(originalObject, (mutation) => {
32058
+ console.log('Change detected:', mutation);
31988
32059
  });
31989
32060
 
32061
+ // // These operations will trigger the callback
32062
+ // observedObject.name = "Jane"; // Property update
32063
+ // observedObject.job = "Developer"; // Property addition
32064
+ // delete observedObject.age; // Property deletion
32065
+ //==================
32066
+
31990
32067
  return {};
31991
32068
  },
31992
32069
  'xu-bind': async function ($elm, val) {