@azrico/webobject 1.5.72 → 1.5.74

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.
@@ -69,6 +69,37 @@ export declare class SimpleObject extends MapableObject {
69
69
  * @returns
70
70
  */
71
71
  static get<T extends SimpleObject, MKey extends PropOf<T>>(obj: T, key: MKey, original?: boolean): PropType<T, MKey> | undefined;
72
+ /**
73
+ * get on any value: a SimpleObject, a plain copy of one that keeps its `__delta`
74
+ * (grid rows, spreads) or a plain object
75
+ */
76
+ static get(obj: any, key: PropertyKey, original?: boolean): any;
77
+ /**
78
+ * static set method, uses `set` of the object when it is a SimpleObject
79
+ * and changes a plain object in place (compared loosely, `"5"` equals `5`)
80
+ * @param obj
81
+ * @param key
82
+ * @param value
83
+ * @param sendChange
84
+ * @returns true if changed , false otherwise
85
+ */
86
+ static set(obj: SimpleObject | any, key: string, value: any, sendChange?: sendChangesType): boolean;
87
+ /**
88
+ * set a key of a child object (a row of an array field, ...) and notify `obj`
89
+ * @param obj the parent object
90
+ * @param child the changed child, changed with `SimpleObject.set`
91
+ * @param key
92
+ * @param value
93
+ * @param object_name the name of the child list, passed to `notifyChanged`
94
+ * @param sendChange
95
+ * @returns true if changed , false otherwise
96
+ */
97
+ static setValueOf(obj: SimpleObject, child: any, key: string, value: any, object_name?: string, sendChange?: sendChangesType): boolean;
98
+ /**
99
+ * set a key of a child object of this object and notify this object
100
+ * @see SimpleObject.setValueOf
101
+ */
102
+ setValueOf(child: any, key: string, value: any, object_name?: string, sendChange?: sendChangesType): boolean;
72
103
  /**
73
104
  * use a property from the object, this will return latest value of the property
74
105
  * uses `EventManager` to detect changes
@@ -127,23 +127,27 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
127
127
  }
128
128
  return is_fnc ? (0, _object.fn_eval_this)(this, used_value) : used_value;
129
129
  }
130
- /**
131
- * static get method for SimpleObject
132
- * @param obj
133
- * @param key
134
- * @param original
135
- * @returns
136
- */
137
130
  }, {
138
- key: "use",
131
+ key: "setValueOf",
139
132
  value:
133
+ /**
134
+ * set a key of a child object of this object and notify this object
135
+ * @see SimpleObject.setValueOf
136
+ */
137
+ function setValueOf(child, key, value) {
138
+ var object_name = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : "";
139
+ var sendChange = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : "auto";
140
+ return SimpleObject.setValueOf(this, child, key, value, object_name, sendChange);
141
+ }
140
142
  /**
141
143
  * use a property from the object, this will return latest value of the property
142
144
  * uses `EventManager` to detect changes
143
145
  *
144
146
  * Only objects with a manager can use this function
145
147
  */
146
- function use(key) {
148
+ }, {
149
+ key: "use",
150
+ value: function use(key) {
147
151
  if (this.manager == null) {
148
152
  console.warn("Objects with no manager should not use useProperty");
149
153
  return this.get(key);
@@ -1362,6 +1366,52 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
1362
1366
  }
1363
1367
  return obj[key];
1364
1368
  }
1369
+ /**
1370
+ * static set method, uses `set` of the object when it is a SimpleObject
1371
+ * and changes a plain object in place (compared loosely, `"5"` equals `5`)
1372
+ * @param obj
1373
+ * @param key
1374
+ * @param value
1375
+ * @param sendChange
1376
+ * @returns true if changed , false otherwise
1377
+ */
1378
+ }, {
1379
+ key: "set",
1380
+ value: function set(obj, key, value) {
1381
+ var sendChange = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : "auto";
1382
+ if (obj instanceof SimpleObject) {
1383
+ var before = obj.get(key);
1384
+ void obj.set(key, value, sendChange);
1385
+ return !(0, _object.object_equals)(before, obj.get(key));
1386
+ }
1387
+ if (!obj) return false;
1388
+ var isValueChanged = !(0, _object.object_equals)(obj[key], value, {
1389
+ ignoredStartingWords: "_",
1390
+ loose: true
1391
+ });
1392
+ if (isValueChanged) obj[key] = value;
1393
+ return isValueChanged;
1394
+ }
1395
+ /**
1396
+ * set a key of a child object (a row of an array field, ...) and notify `obj`
1397
+ * @param obj the parent object
1398
+ * @param child the changed child, changed with `SimpleObject.set`
1399
+ * @param key
1400
+ * @param value
1401
+ * @param object_name the name of the child list, passed to `notifyChanged`
1402
+ * @param sendChange
1403
+ * @returns true if changed , false otherwise
1404
+ */
1405
+ }, {
1406
+ key: "setValueOf",
1407
+ value: function setValueOf(obj, child, key, value) {
1408
+ var object_name = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : "";
1409
+ var sendChange = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : "auto";
1410
+ if (!child) return false;
1411
+ var isValueChanged = SimpleObject.set(child, key, value, false);
1412
+ if (sendChange === true || isValueChanged && sendChange === "auto") void (obj === null || obj === void 0 ? void 0 : obj.notifyChanged(object_name, key, value));
1413
+ return isValueChanged;
1414
+ }
1365
1415
  }, {
1366
1416
  key: "loadValues",
1367
1417
  value: function loadValues(obj, initObject) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azrico/webobject",
3
- "version": "1.5.72",
3
+ "version": "1.5.74",
4
4
  "description": "Stateful object",
5
5
  "author": "Azrideus",
6
6
  "license": "MIT",