@xuda.io/runtime-bundle 1.0.1278 → 1.0.1280

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.
@@ -37,7 +37,6 @@ export const action_execute = async function (SESSION_ID, actionP, params, isScr
37
37
 
38
38
  if (!_ds) {
39
39
  func.events.delete_job(SESSION_ID, jobNoP);
40
-
41
40
  return;
42
41
  }
43
42
 
@@ -28150,50 +28150,126 @@ func.UI.update_xu_ref = function (SESSION_ID, dsSessionP, ref_field_id, $elm) {
28150
28150
  const _ds = func.utils.clean_returned_datasource(SESSION_ID, dsSessionP);
28151
28151
 
28152
28152
  //////////////
28153
+ // function createWatchedObject(obj, onChange) {
28154
+ // return new Proxy(obj, {
28155
+ // set(target, property, value) {
28156
+ // const oldValue = target[property];
28157
+ // target[property] = value;
28158
+
28159
+ // if (oldValue !== value) {
28160
+ // onChange({
28161
+ // property,
28162
+ // oldValue,
28163
+ // newValue: value,
28164
+ // timestamp: new Date(),
28165
+ // });
28166
+ // }
28167
+
28168
+ // return true;
28169
+ // },
28170
+
28171
+ // deleteProperty(target, property) {
28172
+ // const oldValue = target[property];
28173
+ // delete target[property];
28174
+
28175
+ // onChange({
28176
+ // property,
28177
+ // oldValue,
28178
+ // newValue: undefined,
28179
+ // deleted: true,
28180
+ // timestamp: new Date(),
28181
+ // });
28182
+
28183
+ // return true;
28184
+ // },
28185
+ // });
28186
+ // }
28187
+
28188
+ // // Usage
28189
+ // const watchedUser = createWatchedObject(
28190
+ // { name: "John", age: 25 },
28191
+ // (change) => console.log("Change detected:", change)
28192
+ // );
28193
+
28194
+ // watchedUser.age = 26; // Logs: Change detected: { property: "age", oldValue: 25, newValue: 26, ... }
28195
+
28153
28196
  function createWatchedObject(obj, onChange) {
28154
- return new Proxy(obj, {
28155
- set(target, property, value) {
28156
- const oldValue = target[property];
28157
- target[property] = value;
28197
+ const watchers = new WeakMap();
28198
+
28199
+ function createProxy(target, path = []) {
28200
+ if (watchers.has(target)) {
28201
+ return watchers.get(target);
28202
+ }
28203
+
28204
+ const proxy = new Proxy(target, {
28205
+ set(obj, prop, value) {
28206
+ const oldValue = obj[prop];
28207
+ const currentPath = [...path, prop];
28208
+
28209
+ // Set the new value
28210
+ obj[prop] = value;
28211
+
28212
+ // If the new value is an object, make it observable too
28213
+ if (typeof value === 'object' && value !== null) {
28214
+ obj[prop] = createProxy(value, currentPath);
28215
+ }
28216
+
28217
+ // Notify of change
28218
+ if (oldValue !== value) {
28219
+ onChange({
28220
+ path: currentPath.join('.'),
28221
+ oldValue,
28222
+ newValue: value,
28223
+ type: 'set',
28224
+ timestamp: Date.now(),
28225
+ });
28226
+ }
28227
+
28228
+ return true;
28229
+ },
28230
+
28231
+ deleteProperty(obj, prop) {
28232
+ const oldValue = obj[prop];
28233
+ const currentPath = [...path, prop];
28234
+
28235
+ delete obj[prop];
28158
28236
 
28159
- if (oldValue !== value) {
28160
28237
  onChange({
28161
- property,
28238
+ path: currentPath.join('.'),
28162
28239
  oldValue,
28163
- newValue: value,
28164
- timestamp: new Date(),
28240
+ newValue: undefined,
28241
+ type: 'delete',
28242
+ timestamp: Date.now(),
28165
28243
  });
28166
- }
28167
28244
 
28168
- return true;
28169
- },
28245
+ return true;
28246
+ },
28247
+ });
28170
28248
 
28171
- deleteProperty(target, property) {
28172
- const oldValue = target[property];
28173
- delete target[property];
28249
+ // Make nested objects observable
28250
+ for (const [key, value] of Object.entries(target)) {
28251
+ if (typeof value === 'object' && value !== null) {
28252
+ target[key] = createProxy(value, [...path, key]);
28253
+ }
28254
+ }
28174
28255
 
28175
- onChange({
28176
- property,
28177
- oldValue,
28178
- newValue: undefined,
28179
- deleted: true,
28180
- timestamp: new Date(),
28181
- });
28256
+ watchers.set(target, proxy);
28257
+ return proxy;
28258
+ }
28182
28259
 
28183
- return true;
28184
- },
28185
- });
28260
+ return createProxy(obj);
28186
28261
  }
28187
28262
 
28188
- // // Usage
28189
- // const watchedUser = createWatchedObject(
28190
- // { name: "John", age: 25 },
28191
- // (change) => console.log("Change detected:", change)
28192
- // );
28263
+ const watchedUser = createWatchedObject(_ds, async (change) => {
28264
+ console.log('Change detected:', change);
28265
+ try {
28266
+ // _session.DS_GLB[dsSessionP][property] = newValue;
28193
28267
 
28194
- // watchedUser.age = 26; // Logs: Change detected: { property: "age", oldValue: 25, newValue: 26, ... }
28268
+ _.set(_session.DS_GLB[dsSessionP], change.path, change.newValue);
28195
28269
 
28196
- const watchedUser = createWatchedObject(_ds, (change) => console.log('Change detected:', change));
28270
+ await func.action.execute(SESSION_ID, 'act_refresh', _session.DS_GLB[dsSessionP], null, null, null, $elm);
28271
+ } catch (error) {}
28272
+ });
28197
28273
 
28198
28274
  //////////////
28199
28275
 
@@ -40052,30 +40128,9 @@ func.events.invoke = async function (event_id) {
40052
40128
  func.events.validate(SESSION_ID, 'user_defined', ds, event_id);
40053
40129
  };
40054
40130
  func.action = {};
40055
- func.action.execute = async function (
40056
- SESSION_ID,
40057
- actionP,
40058
- paramsP,
40059
- isScreenActionP,
40060
- event_sourceP,
40061
- jobNoP,
40062
- // callbackP,
40063
- containerP
40064
- ) {
40065
- const module = await func.common.get_module(
40066
- SESSION_ID,
40067
- "xuda-actions-module.esm.js"
40068
- );
40069
- await module.action_execute(
40070
- SESSION_ID,
40071
- actionP,
40072
- paramsP,
40073
- isScreenActionP,
40074
- event_sourceP,
40075
- jobNoP,
40076
- // callbackP,
40077
- containerP
40078
- );
40131
+ func.action.execute = async function (SESSION_ID, actionP, paramsP, isScreenActionP, event_sourceP, jobNoP, containerP) {
40132
+ const module = await func.common.get_module(SESSION_ID, 'xuda-actions-module.esm.js');
40133
+ await module.action_execute(SESSION_ID, actionP, paramsP, isScreenActionP, event_sourceP, jobNoP, containerP);
40079
40134
  };
40080
40135
  func.fcm = {};
40081
40136
  // func.fcm.load_resources = function (callbackP) {