@azrico/webobject 1.5.72 → 1.5.73

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,32 @@ 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
+ * static set method, uses `set` of the object when it is a SimpleObject
74
+ * and changes a plain object in place (compared loosely, `"5"` equals `5`)
75
+ * @param obj
76
+ * @param key
77
+ * @param value
78
+ * @param sendChange
79
+ * @returns true if changed , false otherwise
80
+ */
81
+ static set(obj: SimpleObject | any, key: string, value: any, sendChange?: sendChangesType): boolean;
82
+ /**
83
+ * set a key of a child object (a row of an array field, ...) and notify `obj`
84
+ * @param obj the parent object
85
+ * @param child the changed child, changed with `SimpleObject.set`
86
+ * @param key
87
+ * @param value
88
+ * @param object_name the name of the child list, passed to `notifyChanged`
89
+ * @param sendChange
90
+ * @returns true if changed , false otherwise
91
+ */
92
+ static setValueOf(obj: SimpleObject, child: any, key: string, value: any, object_name?: string, sendChange?: sendChangesType): boolean;
93
+ /**
94
+ * set a key of a child object of this object and notify this object
95
+ * @see SimpleObject.setValueOf
96
+ */
97
+ setValueOf(child: any, key: string, value: any, object_name?: string, sendChange?: sendChangesType): boolean;
72
98
  /**
73
99
  * use a property from the object, this will return latest value of the property
74
100
  * uses `EventManager` to detect changes
@@ -135,15 +135,26 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
135
135
  * @returns
136
136
  */
137
137
  }, {
138
- key: "use",
138
+ key: "setValueOf",
139
139
  value:
140
+ /**
141
+ * set a key of a child object of this object and notify this object
142
+ * @see SimpleObject.setValueOf
143
+ */
144
+ function setValueOf(child, key, value) {
145
+ var object_name = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : "";
146
+ var sendChange = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : "auto";
147
+ return SimpleObject.setValueOf(this, child, key, value, object_name, sendChange);
148
+ }
140
149
  /**
141
150
  * use a property from the object, this will return latest value of the property
142
151
  * uses `EventManager` to detect changes
143
152
  *
144
153
  * Only objects with a manager can use this function
145
154
  */
146
- function use(key) {
155
+ }, {
156
+ key: "use",
157
+ value: function use(key) {
147
158
  if (this.manager == null) {
148
159
  console.warn("Objects with no manager should not use useProperty");
149
160
  return this.get(key);
@@ -1362,6 +1373,52 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
1362
1373
  }
1363
1374
  return obj[key];
1364
1375
  }
1376
+ /**
1377
+ * static set method, uses `set` of the object when it is a SimpleObject
1378
+ * and changes a plain object in place (compared loosely, `"5"` equals `5`)
1379
+ * @param obj
1380
+ * @param key
1381
+ * @param value
1382
+ * @param sendChange
1383
+ * @returns true if changed , false otherwise
1384
+ */
1385
+ }, {
1386
+ key: "set",
1387
+ value: function set(obj, key, value) {
1388
+ var sendChange = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : "auto";
1389
+ if (obj instanceof SimpleObject) {
1390
+ var before = obj.get(key);
1391
+ void obj.set(key, value, sendChange);
1392
+ return !(0, _object.object_equals)(before, obj.get(key));
1393
+ }
1394
+ if (!obj) return false;
1395
+ var isValueChanged = !(0, _object.object_equals)(obj[key], value, {
1396
+ ignoredStartingWords: "_",
1397
+ loose: true
1398
+ });
1399
+ if (isValueChanged) obj[key] = value;
1400
+ return isValueChanged;
1401
+ }
1402
+ /**
1403
+ * set a key of a child object (a row of an array field, ...) and notify `obj`
1404
+ * @param obj the parent object
1405
+ * @param child the changed child, changed with `SimpleObject.set`
1406
+ * @param key
1407
+ * @param value
1408
+ * @param object_name the name of the child list, passed to `notifyChanged`
1409
+ * @param sendChange
1410
+ * @returns true if changed , false otherwise
1411
+ */
1412
+ }, {
1413
+ key: "setValueOf",
1414
+ value: function setValueOf(obj, child, key, value) {
1415
+ var object_name = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : "";
1416
+ var sendChange = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : "auto";
1417
+ if (!child) return false;
1418
+ var isValueChanged = SimpleObject.set(child, key, value, false);
1419
+ if (sendChange === true || isValueChanged && sendChange === "auto") void (obj === null || obj === void 0 ? void 0 : obj.notifyChanged(object_name, key, value));
1420
+ return isValueChanged;
1421
+ }
1365
1422
  }, {
1366
1423
  key: "loadValues",
1367
1424
  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.73",
4
4
  "description": "Stateful object",
5
5
  "author": "Azrideus",
6
6
  "license": "MIT",