@azrico/webobject 1.5.5 → 1.5.6

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.
@@ -125,10 +125,10 @@ var WebObject = exports.WebObject = /*#__PURE__*/function (_SimpleObject) {
125
125
  return _context.abrupt("return", false);
126
126
  case 16:
127
127
  //same value, no changes
128
- new_metalist = _objectSpread({}, this.getValue("meta_data"));
128
+ new_metalist = _objectSpread({}, this.get("meta_data"));
129
129
  new_metalist[key] = value;
130
130
  _context.next = 20;
131
- return this.setValue("meta_data", new_metalist);
131
+ return this.set("meta_data", new_metalist);
132
132
  case 20:
133
133
  if (!(sendChange !== false)) {
134
134
  _context.next = 23;
@@ -1105,7 +1105,7 @@ var WebObject = exports.WebObject = /*#__PURE__*/function (_SimpleObject) {
1105
1105
  if (!key || typeof key != "string") return undefined;
1106
1106
  var metalist = {};
1107
1107
  if (_typeof(o) === "object") {
1108
- metalist = typeof o.getValue === "function" ? o.getValue("meta_data") : o.meta_data;
1108
+ metalist = typeof o.get === "function" ? o.get("meta_data") : o.meta_data;
1109
1109
  }
1110
1110
  return metalist[key];
1111
1111
  }
@@ -47,15 +47,14 @@ export declare class ObjectManager<ObjType extends SimpleObject> extends RawObje
47
47
  getSaveResultType(): saveResultType | null;
48
48
  setSaveResult(toObj: any, type: saveResultType): saveResultType | undefined;
49
49
  apply_changes(): boolean;
50
- getValue(key: PropOf<ObjType>, original?: boolean): import("@azrico/types").PropType<ObjType, any> | null;
51
- get: (key: PropOf<ObjType>, original?: boolean) => import("@azrico/types").PropType<ObjType, any> | null;
50
+ get(key: PropOf<ObjType>, original?: boolean): import("@azrico/types").PropType<ObjType, any> | null;
52
51
  /**
53
52
  * set value
54
53
  * @param key
55
54
  * @param value
56
55
  * @return true if changed , false otherwise
57
56
  */
58
- setValue(key: WriteablePropOf<ObjType>, value: any): Promise<boolean>;
57
+ set(key: WriteablePropOf<ObjType>, value: any): Promise<boolean>;
59
58
  /**
60
59
  * set key of subObject
61
60
  * @param key
@@ -46,7 +46,6 @@ var ObjectManager = exports.ObjectManager = /*#__PURE__*/function (_RawObject) {
46
46
  _defineProperty(_this, "__options", void 0);
47
47
  //can the current object be set to null safely?
48
48
  _defineProperty(_this, "__object_nullable", false);
49
- _defineProperty(_this, "get", _this.getValue);
50
49
  _this.setObject(defaultObject);
51
50
  return _this;
52
51
  }
@@ -66,7 +65,7 @@ var ObjectManager = exports.ObjectManager = /*#__PURE__*/function (_RawObject) {
66
65
  }
67
66
  return _context.abrupt("return", false);
68
67
  case 3:
69
- if (value === undefined && type != "meta") value = obj.getValue(key);
68
+ if (value === undefined && type != "meta") value = obj.get(key);
70
69
  typestr = (type ? "$".concat(type, "$") : "") + String(key);
71
70
  _context.next = 7;
72
71
  return this.event_run("on_change", typestr, value);
@@ -196,41 +195,40 @@ var ObjectManager = exports.ObjectManager = /*#__PURE__*/function (_RawObject) {
196
195
  return ((_this$obj7 = this.obj) === null || _this$obj7 === void 0 ? void 0 : _this$obj7.apply_changes()) || false;
197
196
  }
198
197
  }, {
199
- key: "getValue",
200
- value: function getValue(key) {
198
+ key: "get",
199
+ value: function get(key) {
201
200
  var original = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
202
201
  var thisobj = this.obj;
203
- if (thisobj == null || typeof thisobj.getValue != "function") {
204
- if (!this.__object_nullable) console.error("cant use getValue when object is not defined. maybe you have to use New() ?");
202
+ if (thisobj == null || typeof thisobj.get != "function") {
203
+ if (!this.__object_nullable) console.error("cant use get when object is not defined. maybe you have to use New() ?");
205
204
  return null;
206
205
  }
207
- return thisobj.getValue(key, original);
206
+ return thisobj.get(key, original);
208
207
  }
209
- }, {
210
- key: "setValue",
211
- value: (
212
208
  /**
213
209
  * set value
214
210
  * @param key
215
211
  * @param value
216
212
  * @return true if changed , false otherwise
217
213
  */
218
- function () {
219
- var _setValue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(key, value) {
214
+ }, {
215
+ key: "set",
216
+ value: (function () {
217
+ var _set = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(key, value) {
220
218
  var thisobj;
221
219
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
222
220
  while (1) switch (_context2.prev = _context2.next) {
223
221
  case 0:
224
222
  thisobj = this.obj;
225
- if (!(thisobj == null || typeof thisobj.setValue != "function")) {
223
+ if (!(thisobj == null || typeof thisobj.set != "function")) {
226
224
  _context2.next = 4;
227
225
  break;
228
226
  }
229
- if (!this.__object_nullable) console.error("cant use setValue when object is not defined. maybe you have to use New() ?");
227
+ if (!this.__object_nullable) console.error("cant use set when object is not defined. maybe you have to use New() ?");
230
228
  return _context2.abrupt("return", false);
231
229
  case 4:
232
230
  _context2.next = 6;
233
- return thisobj.setValue(key, value);
231
+ return thisobj.set(key, value);
234
232
  case 6:
235
233
  _context2.t0 = _context2.sent;
236
234
  if (_context2.t0) {
@@ -246,10 +244,10 @@ var ObjectManager = exports.ObjectManager = /*#__PURE__*/function (_RawObject) {
246
244
  }
247
245
  }, _callee2, this);
248
246
  }));
249
- function setValue(_x5, _x6) {
250
- return _setValue.apply(this, arguments);
247
+ function set(_x5, _x6) {
248
+ return _set.apply(this, arguments);
251
249
  }
252
- return setValue;
250
+ return set;
253
251
  }()
254
252
  /**
255
253
  * set key of subObject
@@ -1,4 +1,4 @@
1
- import { PropType, WriteablePropOf, PropOf, Ensure } from "@azrico/types";
1
+ import { PropType, WriteablePropOf, PropOf, Ensure, PropOnlyPrefixedOf } from "@azrico/types";
2
2
  import { formatObject } from "@azrico/convert";
3
3
  import { MapableObject } from "./MapableObject";
4
4
  import ObjectManager from "./ObjectManager";
@@ -47,9 +47,9 @@ export declare class SimpleObject extends MapableObject {
47
47
  _index_key: string;
48
48
  _index_value: number;
49
49
  constructor(is_readonly?: boolean);
50
- getValue: <MKey extends keyof this>(key: MKey, original?: boolean) => PropType<this, MKey>;
51
- get: <MKey extends keyof this>(key: MKey, original?: boolean) => PropType<this, MKey>;
52
- static getValue<T extends SimpleObject, MKey extends PropOf<T>>(o: T, key: MKey, original?: boolean): PropType<T, MKey> | undefined;
50
+ get<MKey extends PropOf<this>>(key: MKey, original?: boolean): PropType<this, MKey>;
51
+ get<MKey extends PropOnlyPrefixedOf<this>>(key: MKey, original?: boolean): any;
52
+ static get<T extends SimpleObject, MKey extends PropOf<T>>(o: T, key: MKey, original?: boolean): PropType<T, MKey> | undefined;
53
53
  /**
54
54
  * set value and run the event handlers if needed
55
55
  * @param key
@@ -58,7 +58,7 @@ export declare class SimpleObject extends MapableObject {
58
58
  * @param autoApply if the field is not in delta, instantly calls the `apply` function to remove from delta
59
59
  * @returns
60
60
  */
61
- setValue(key: WriteablePropOf<this>, value: any, shouldNotify?: sendChangesType, autoApply?: boolean): Promise<boolean>;
61
+ set(key: WriteablePropOf<this>, value: any, shouldNotify?: sendChangesType, autoApply?: boolean): Promise<boolean>;
62
62
  /**
63
63
  * set value and run the event handlers if needed
64
64
  *
@@ -71,7 +71,7 @@ export declare class SimpleObject extends MapableObject {
71
71
  * set value and run the event handlers if needed
72
72
  * @return true if changed , false otherwise
73
73
  */
74
- set: (key: WriteablePropOf<this>, value: any, shouldNotify?: sendChangesType, autoApply?: boolean) => Promise<boolean>;
74
+ setValue: (key: WriteablePropOf<this>, value: any, shouldNotify?: sendChangesType, autoApply?: boolean) => Promise<boolean>;
75
75
  /**
76
76
  * load all properties in `initObject` into the current object
77
77
  * @param initObject
@@ -86,7 +86,7 @@ export declare class SimpleObject extends MapableObject {
86
86
  addRefreshFunction(new_fnc: any): any;
87
87
  runRefreshFunction(...params: any): Promise<void>;
88
88
  /**
89
- * calls `setValue` function for all props of `setObj`
89
+ * calls `set` function for all props of `setObj`
90
90
  * @param setObj
91
91
  * @param changeablesOnly only updates the `__changeables` fields
92
92
  * @returns
@@ -81,13 +81,11 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
81
81
  _defineProperty(_this, "_index_key", "");
82
82
  //sequence value , used to index the object with increasing numbers
83
83
  _defineProperty(_this, "_index_value", -1);
84
- _defineProperty(_this, "getValue", _assertClassBrand(_SimpleObject_brand, _this, _getProperty));
85
- _defineProperty(_this, "get", _assertClassBrand(_SimpleObject_brand, _this, _getProperty));
86
84
  /**
87
85
  * set value and run the event handlers if needed
88
86
  * @return true if changed , false otherwise
89
87
  */
90
- _defineProperty(_this, "set", _this.setValue);
88
+ _defineProperty(_this, "setValue", _this.set);
91
89
  /**
92
90
  * set value of a key to now date time
93
91
  * @param key
@@ -118,7 +116,29 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
118
116
  return this.constructor;
119
117
  }
120
118
  }, {
121
- key: "setValue",
119
+ key: "get",
120
+ value: function get(key) {
121
+ var original = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
122
+ //check if we should treat the prop as a function
123
+ var is_fnc = this.constructor["__functionProperties"] != null && this.constructor["__functionProperties"].includes(key);
124
+ //check if we should use delta version or normal version for this property
125
+ var used_value;
126
+ if (typeof key === "string" && key.includes(".")) {
127
+ /* ----------------------------- using sub value ---------------------------- */
128
+ var keysp = key.split(".");
129
+ var subkey_part = keysp.pop();
130
+ var key_part = keysp.join(".");
131
+ used_value = _assertClassBrand(_SimpleObject_brand, this, _getSubProperty).call(this, key_part, subkey_part);
132
+ } else {
133
+ /* --------------------------- using this or delta -------------------------- */
134
+ var self_key = key;
135
+ var use_orig = original || !this.__use_delta || !(self_key in this.__delta);
136
+ used_value = use_orig ? this[self_key] : this.__delta[self_key];
137
+ }
138
+ return is_fnc ? (0, _object.fn_eval_this)(this, used_value) : used_value;
139
+ }
140
+ }, {
141
+ key: "set",
122
142
  value: (
123
143
  /**
124
144
  * set value and run the event handlers if needed
@@ -129,7 +149,7 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
129
149
  * @returns
130
150
  */
131
151
  function () {
132
- var _setValue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(key, value) {
152
+ var _set = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(key, value) {
133
153
  var shouldNotify,
134
154
  autoApply,
135
155
  keyExists,
@@ -150,13 +170,13 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
150
170
  _context.next = 7;
151
171
  break;
152
172
  }
153
- throw Error("Cant use setValue (".concat(String(key), ") when on readonly mode"));
173
+ throw Error("Cant use set (".concat(String(key), ") when on readonly mode"));
154
174
  case 7:
155
175
  return _context.abrupt("return", false);
156
176
  case 8:
157
177
  /* --------------------------- set if not changed --------------------------- */
158
178
  keyExists = key in this.__delta;
159
- old_value = this.getValue(key);
179
+ old_value = this.get(key);
160
180
  needsChange = !(0, _object.object_equals)(old_value, value, {
161
181
  strictArrayCheck: true,
162
182
  ignoredStartingWords: "_"
@@ -192,10 +212,10 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
192
212
  }
193
213
  }, _callee, this);
194
214
  }));
195
- function setValue(_x, _x2) {
196
- return _setValue.apply(this, arguments);
215
+ function set(_x, _x2) {
216
+ return _set.apply(this, arguments);
197
217
  }
198
- return setValue;
218
+ return set;
199
219
  }()
200
220
  /**
201
221
  * set value and run the event handlers if needed
@@ -400,7 +420,7 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
400
420
  }()
401
421
  /* -------------------------------------------------------------------------- */
402
422
  /**
403
- * calls `setValue` function for all props of `setObj`
423
+ * calls `set` function for all props of `setObj`
404
424
  * @param setObj
405
425
  * @param changeablesOnly only updates the `__changeables` fields
406
426
  * @returns
@@ -429,7 +449,7 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
429
449
  }
430
450
  key = checkKeys[index];
431
451
  _context8.next = 8;
432
- return this.setValue(key, setObj[key]);
452
+ return this.set(key, setObj[key]);
433
453
  case 8:
434
454
  if (_context8.sent) {
435
455
  _context8.next = 10;
@@ -601,8 +621,8 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
601
621
  case 8:
602
622
  return _context11.abrupt("return", false);
603
623
  case 9:
604
- if (_assertClassBrand(_SimpleObject_brand, this, _getProperty).call(this, key) == null) _assertClassBrand(_SimpleObject_brand, this, _setProperty).call(this, key, []);
605
- tempArray = _assertClassBrand(_SimpleObject_brand, this, _getProperty).call(this, key);
624
+ if (this.get(key) == null) _assertClassBrand(_SimpleObject_brand, this, _setProperty).call(this, key, []);
625
+ tempArray = this.get(key);
606
626
  if (Array.isArray(tempArray)) {
607
627
  _context11.next = 17;
608
628
  break;
@@ -652,7 +672,7 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
652
672
  return _regeneratorRuntime().wrap(function _callee12$(_context12) {
653
673
  while (1) switch (_context12.prev = _context12.next) {
654
674
  case 0:
655
- if (value === undefined && type == "") value = this.getValue(key);
675
+ if (value === undefined && type == "") value = this.get(key);
656
676
  lc = "";
657
677
  if (type) lc += "$".concat(String(type), "$");
658
678
  if (subvalue) {
@@ -751,7 +771,7 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
751
771
  case 0:
752
772
  shouldNotify = _args13.length > 1 && _args13[1] !== undefined ? _args13[1] : "auto";
753
773
  _context13.next = 3;
754
- return this.setValue(key, this[key], shouldNotify);
774
+ return this.set(key, this[key], shouldNotify);
755
775
  case 3:
756
776
  return _context13.abrupt("return", _context13.sent);
757
777
  case 4:
@@ -1205,11 +1225,12 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
1205
1225
  /* statics */
1206
1226
  /* -------------------------------------------------------------------------- */
1207
1227
  }], [{
1208
- key: "getValue",
1209
- value: function getValue(o, key) {
1228
+ key: "get",
1229
+ value: function get(o, key) {
1210
1230
  var original = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
1211
1231
  if (o == null) return undefined;
1212
- if (o instanceof SimpleObject && typeof o.getValue === "function") return o.getValue(key, original);
1232
+ if (o instanceof SimpleObject && typeof o.get === "function") return o.get(key, original);
1233
+ /* ------------------------------- manual get ------------------------------- */
1213
1234
  if (!original && o.__use_delta != false && _typeof(o.__delta) === "object" && key in o.__delta) {
1214
1235
  //@ts-ignore
1215
1236
  return o.__delta[key];
@@ -1217,7 +1238,7 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
1217
1238
  return o[key];
1218
1239
  }
1219
1240
  /* -------------------------------------------------------------------------- */
1220
- /* setValue */
1241
+ /* set */
1221
1242
  /* -------------------------------------------------------------------------- */
1222
1243
  }, {
1223
1244
  key: "loadValues",
@@ -1618,24 +1639,8 @@ function _setDefaultPropertyNow(key) {
1618
1639
  }
1619
1640
  return false;
1620
1641
  }
1621
- /* -------------------------------------------------------------------------- */
1622
- /* getProperty */
1623
- /* -------------------------------------------------------------------------- */
1624
- function _getProperty(key) {
1625
- var original = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1626
- //check if we should treat the prop as a function
1627
- var is_fnc = this.constructor["__functionProperties"] != null && this.constructor["__functionProperties"].includes(key);
1628
- //check if we should use delta version or normal version for this property
1629
- var use_orig = original || !this.__use_delta || !(key in this.__delta);
1630
- if (is_fnc) {
1631
- if (use_orig) return (0, _object.fn_eval_this)(this, this[key]);
1632
- return (0, _object.fn_eval_this)(this, this.__delta[key]);
1633
- }
1634
- if (use_orig) return this[key];
1635
- return this.__delta[key];
1636
- }
1637
1642
  function _setSubProperty(key, subkey, value) {
1638
- var subobj = _assertClassBrand(_SimpleObject_brand, this, _getProperty).call(this, key);
1643
+ var subobj = this.get(key);
1639
1644
  //@ts-ignore
1640
1645
  if (subobj == null || _typeof(subobj) !== "object") subobj = {};else subobj = _objectSpread({}, subobj); //make a clone so we dont update the original
1641
1646
  subobj[subkey] = value;
@@ -1643,7 +1648,7 @@ function _setSubProperty(key, subkey, value) {
1643
1648
  }
1644
1649
  function _getSubProperty(key, subkey) {
1645
1650
  var original = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
1646
- var subobj = _assertClassBrand(_SimpleObject_brand, this, _getProperty).call(this, key, original);
1651
+ var subobj = this.get(key, original);
1647
1652
  if (subobj == null || _typeof(subobj) !== "object") return undefined;
1648
1653
  return subobj[subkey];
1649
1654
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azrico/webobject",
3
- "version": "1.5.5",
3
+ "version": "1.5.6",
4
4
  "description": "Stateful object",
5
5
  "author": "Azrideus",
6
6
  "license": "MIT",
@@ -69,13 +69,13 @@
69
69
  "@azrico/uid": "*"
70
70
  },
71
71
  "dependencies": {
72
- "@azrico/convert": "^1.0.9",
73
- "@azrico/event": "^1.2.44",
74
- "@azrico/global": "^1.3.79",
72
+ "@azrico/convert": "^1.0.13",
73
+ "@azrico/event": "^1.2.52",
74
+ "@azrico/global": "^1.3.85",
75
75
  "@azrico/math": "^1.0.5",
76
- "@azrico/object": "^1.4.107",
77
- "@azrico/string": "^1.2.102",
78
- "@azrico/types": "^1.0.9",
76
+ "@azrico/object": "^1.4.112",
77
+ "@azrico/string": "^1.2.115",
78
+ "@azrico/types": "^1.0.11",
79
79
  "@azrico/uid": "^1.0.8"
80
80
  },
81
81
  "packageManager": "yarn@3.5.0"