@azrico/webobject 1.4.166 → 1.4.168

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.
@@ -26,7 +26,7 @@ export declare class WebObjectManager<T extends WebObject> extends ObjectManager
26
26
  UnLock(): Promise<any>;
27
27
  Archive(): Promise<any>;
28
28
  UnArchive(): Promise<any>;
29
- Load(search: any, ...p: any[]): Promise<WebObject | undefined>;
29
+ Load(id: any, ...p: any[]): Promise<WebObject | undefined>;
30
30
  get __web_path(): string;
31
31
  get __db_name(): string;
32
32
  get __object_name(): string;
@@ -7,6 +7,7 @@ exports["default"] = exports.WebObjectManager = void 0;
7
7
  var _index = require("../index");
8
8
  var _ObjectManager2 = _interopRequireDefault(require("../structs/ObjectManager"));
9
9
  var _global = require("@azrico/global");
10
+ var _object = require("@azrico/object");
10
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
11
12
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
12
13
  function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
@@ -458,16 +459,48 @@ var WebObjectManager = exports.WebObjectManager = /*#__PURE__*/function (_Object
458
459
  }, {
459
460
  key: "Load",
460
461
  value: (function () {
461
- var _Load = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(search) {
462
+ var _Load = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(id) {
463
+ var classType, result_product;
462
464
  return _regeneratorRuntime().wrap(function _callee13$(_context13) {
463
465
  while (1) switch (_context13.prev = _context13.next) {
464
466
  case 0:
465
- throw Error("load not implented");
466
- case 1:
467
+ if (id) {
468
+ _context13.next = 2;
469
+ break;
470
+ }
471
+ return _context13.abrupt("return");
472
+ case 2:
473
+ _context13.prev = 2;
474
+ this.event_run("on_process_start", true);
475
+ classType = (0, _object.object_getStatic)(this, "__object_type");
476
+ _context13.next = 7;
477
+ return classType.get_single(id, false);
478
+ case 7:
479
+ result_product = _context13.sent;
480
+ if (!(result_product && _typeof(result_product) === "object" && _index.WebObject.getID(result_product))) {
481
+ _context13.next = 14;
482
+ break;
483
+ }
484
+ this.setObject(result_product);
485
+ _context13.next = 12;
486
+ return result_product.onLoad();
487
+ case 12:
488
+ _context13.next = 16;
489
+ break;
490
+ case 14:
491
+ console.error("badobject:", id, result_product);
492
+ _index.WebObject.addError(this.obj, "Invalid ".concat(this.__object_name), "The loaded ".concat(this.__object_name, " from website is invalid"), true);
493
+ case 16:
494
+ _context13.prev = 16;
495
+ this.event_run("on_process_end", true);
496
+ return _context13.finish(16);
497
+ case 19:
498
+ return _context13.abrupt("return", this.getObject());
499
+ case 20:
467
500
  case "end":
468
501
  return _context13.stop();
469
502
  }
470
- }, _callee13);
503
+ }, _callee13, this, [[2,, 16, 19]]);
471
504
  }));
472
505
  function Load(_x7) {
473
506
  return _Load.apply(this, arguments);
@@ -96,7 +96,14 @@ export declare class ObjectManager<ObjType extends SimpleObject> extends RawObje
96
96
  * @returns
97
97
  */
98
98
  toggleOption(key: string, value: any): Promise<void>;
99
- setOption(key: string, value: any): Promise<any[] | undefined>;
99
+ getOption(key: string): any;
100
+ /**
101
+ * updates `__options` and runs the `event_run`
102
+ * @param key
103
+ * @param value
104
+ * @returns true if changed, false otherwise
105
+ */
106
+ setOption(key: string, value: any): Promise<boolean>;
100
107
  /**
101
108
  * use an option and detect its changes in real time. similar to recat state
102
109
  * @param key name of the option
@@ -112,7 +119,6 @@ export declare class ObjectManager<ObjType extends SimpleObject> extends RawObje
112
119
  * @param action
113
120
  */
114
121
  holdOption(key: string, value: any, nextvalue: any, action: Function): Promise<void>;
115
- getOption(key: string): any;
116
122
  addError(title?: string, message?: string, sendToRegister?: boolean | "auto"): any[] | undefined;
117
123
  getErrors(): any[];
118
124
  clearErrors(): boolean;
@@ -596,24 +596,40 @@ var ObjectManager = exports.ObjectManager = /*#__PURE__*/function (_RawObject) {
596
596
  }
597
597
  return toggleOption;
598
598
  }())
599
+ }, {
600
+ key: "getOption",
601
+ value: function getOption(key) {
602
+ if (this.__options == null) return undefined;
603
+ key = key.toLowerCase();
604
+ return this.__options[key];
605
+ }
606
+ /**
607
+ * updates `__options` and runs the `event_run`
608
+ * @param key
609
+ * @param value
610
+ * @returns true if changed, false otherwise
611
+ */
599
612
  }, {
600
613
  key: "setOption",
601
- value: function () {
614
+ value: (function () {
602
615
  var _setOption = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(key, value) {
616
+ var isChanged;
603
617
  return _regeneratorRuntime().wrap(function _callee10$(_context10) {
604
618
  while (1) switch (_context10.prev = _context10.next) {
605
619
  case 0:
606
620
  if (this.__options == null) this.__options = {};
621
+ key = key.toLowerCase();
622
+ isChanged = this.__options[key] !== value;
607
623
  if (value == null) {
608
624
  delete this.__options[key];
609
625
  } else {
610
626
  this.__options[key] = value;
611
627
  }
612
- _context10.next = 4;
628
+ _context10.next = 6;
613
629
  return this.event_run("on_option_change", key, value);
614
- case 4:
615
- return _context10.abrupt("return", _context10.sent);
616
- case 5:
630
+ case 6:
631
+ return _context10.abrupt("return", isChanged);
632
+ case 7:
617
633
  case "end":
618
634
  return _context10.stop();
619
635
  }
@@ -629,6 +645,7 @@ var ObjectManager = exports.ObjectManager = /*#__PURE__*/function (_RawObject) {
629
645
  * @param key name of the option
630
646
  * @returns value of the option
631
647
  */
648
+ )
632
649
  }, {
633
650
  key: "useOption",
634
651
  value: function useOption(key) {
@@ -674,16 +691,11 @@ var ObjectManager = exports.ObjectManager = /*#__PURE__*/function (_RawObject) {
674
691
  return _holdOption.apply(this, arguments);
675
692
  }
676
693
  return holdOption;
677
- }())
678
- }, {
679
- key: "getOption",
680
- value: function getOption(key) {
681
- if (this.__options == null) return undefined;
682
- return this.__options[key];
683
- }
694
+ }()
684
695
  /* -------------------------------------------------------------------------- */
685
696
  /* Errors */
686
697
  /* -------------------------------------------------------------------------- */
698
+ )
687
699
  }, {
688
700
  key: "addError",
689
701
  value: function addError(title, message) {
@@ -708,10 +720,8 @@ var ObjectManager = exports.ObjectManager = /*#__PURE__*/function (_RawObject) {
708
720
  }, {
709
721
  key: "useIsChanged",
710
722
  value: function useIsChanged() {
711
- var _this4 = this;
712
- return this.event_use("on_{change,save,load}", function () {
713
- return _this4.isChanged;
714
- });
723
+ return this.useOption("ischanged");
724
+ //// return this.event_use("on_{change,save,load}", () => this.isChanged);
715
725
  }
716
726
  /* -------------------------------------------------------------------------- */
717
727
  }], [{
@@ -24,7 +24,7 @@ export declare class SimpleObject extends MapableObject {
24
24
  _static(): Function;
25
25
  protected __originalobject?: this;
26
26
  protected __delta: Partial<this>;
27
- protected __changed: boolean;
27
+ protected __has_delta: boolean;
28
28
  protected __lastChanged?: string;
29
29
  protected __is_readonly?: boolean;
30
30
  protected __throw_errors?: boolean;
@@ -44,31 +44,27 @@ export declare class SimpleObject extends MapableObject {
44
44
  _index_key: string;
45
45
  _index_value: number;
46
46
  constructor(is_readonly?: boolean);
47
- /**
48
- * load all properties in `initObject` into the current object
49
- * @param initObject
50
- * @param fullUpdate
51
- * @returns
52
- */
53
- loadValues(initObject: any, fullUpdate?: boolean): boolean;
54
- static loadValues(obj: SimpleObject, initObject: any, fullUpdate?: boolean): boolean;
55
- static getValue<T extends SimpleObject, MKey extends PropOf<T>>(o: T, key: MKey, original?: boolean): PropType<T, MKey> | undefined;
56
47
  getValue: <MKey extends keyof this>(key: MKey, original?: boolean) => PropType<this, MKey>;
57
48
  get: <MKey extends keyof this>(key: MKey, original?: boolean) => PropType<this, MKey>;
49
+ static getValue<T extends SimpleObject, MKey extends PropOf<T>>(o: T, key: MKey, original?: boolean): PropType<T, MKey> | undefined;
58
50
  /**
59
- * set value
60
- * @param key
61
- * @param value
51
+ * set value and run the event handlers if needed
62
52
  * @return true if changed , false otherwise
63
53
  */
64
54
  setValue(key: WriteablePropOf<this>, value: any, shouldNotify?: sendChangesType): Promise<boolean>;
65
55
  /**
66
- * set value
67
- * @param key
68
- * @param value
56
+ * set value and run the event handlers if needed
69
57
  * @return true if changed , false otherwise
70
58
  */
71
59
  set: (key: WriteablePropOf<this>, value: any, shouldNotify?: sendChangesType) => Promise<boolean>;
60
+ /**
61
+ * load all properties in `initObject` into the current object
62
+ * @param initObject
63
+ * @param fullUpdate
64
+ * @returns
65
+ */
66
+ loadValues(initObject: any, fullUpdate?: boolean): boolean;
67
+ static loadValues(obj: SimpleObject, initObject: any, fullUpdate?: boolean): boolean;
72
68
  setTemp(key: string, value: any, sendChanges?: sendChangesType): Promise<boolean>;
73
69
  clearRefreshFunction(): Promise<void>;
74
70
  setRefreshFunction(new_fnc: any): Promise<any>;
@@ -46,7 +46,7 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
46
46
  _defineProperty(_this, "__originalobject", void 0);
47
47
  //changes are saved here
48
48
  _defineProperty(_this, "__delta", {});
49
- _defineProperty(_this, "__changed", false);
49
+ _defineProperty(_this, "__has_delta", false);
50
50
  //the last thing that was changed on this object
51
51
  _defineProperty(_this, "__lastChanged", void 0);
52
52
  //is the object read only
@@ -77,9 +77,7 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
77
77
  _defineProperty(_this, "getValue", _assertClassBrand(_SimpleObject_brand, _this, _getProperty));
78
78
  _defineProperty(_this, "get", _assertClassBrand(_SimpleObject_brand, _this, _getProperty));
79
79
  /**
80
- * set value
81
- * @param key
82
- * @param value
80
+ * set value and run the event handlers if needed
83
81
  * @return true if changed , false otherwise
84
82
  */
85
83
  _defineProperty(_this, "set", _this.setValue);
@@ -112,35 +110,20 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
112
110
  value: function _static() {
113
111
  return this.constructor;
114
112
  }
115
- }, {
116
- key: "loadValues",
117
- value: /* -------------------------------------------------------------------------- */
118
- /* Load */
119
- /* -------------------------------------------------------------------------- */
120
- /**
121
- * load all properties in `initObject` into the current object
122
- * @param initObject
123
- * @param fullUpdate
124
- * @returns
125
- */
126
- function loadValues(initObject) {
127
- var fullUpdate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
128
- return SimpleObject.loadValues(this, initObject, fullUpdate);
129
- }
130
113
  }, {
131
114
  key: "setValue",
132
115
  value: (
133
116
  /**
134
- * set value
135
- * @param key
136
- * @param value
117
+ * set value and run the event handlers if needed
137
118
  * @return true if changed , false otherwise
138
119
  */
139
120
  function () {
140
121
  var _setValue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(key, value) {
141
122
  var shouldNotify,
142
- isValueChanged,
143
- oldval,
123
+ old_value,
124
+ needsChange,
125
+ _this$manager,
126
+ __has_delta_isChanged,
144
127
  _args = arguments;
145
128
  return _regeneratorRuntime().wrap(function _callee$(_context) {
146
129
  while (1) switch (_context.prev = _context.next) {
@@ -158,25 +141,32 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
158
141
  case 6:
159
142
  return _context.abrupt("return", false);
160
143
  case 7:
161
- isValueChanged = false;
162
144
  /* --------------------------- set if not changed --------------------------- */
163
- oldval = this.getValue(key);
164
- if (!(0, _object.object_equals)(oldval, value, {
145
+ old_value = this.getValue(key);
146
+ needsChange = !(0, _object.object_equals)(old_value, value, {
165
147
  strictArrayCheck: true,
166
148
  ignoredStartingWords: "_"
167
- })) {
168
- _assertClassBrand(_SimpleObject_brand, this, _setProperty).call(this, key, value);
169
- isValueChanged = true;
170
- } else isValueChanged = false;
149
+ });
150
+ if (needsChange) {
151
+ __has_delta_isChanged = _assertClassBrand(_SimpleObject_brand, this, _setProperty).call(this, key, value);
152
+ /**
153
+ * notify the manager when the state of `__has_delta` is changed
154
+ * managers can use this to detect if they need to save
155
+ */
156
+ (_this$manager = this.manager) === null || _this$manager === void 0 || _this$manager.setOption("ischanged", this.isChanged);
157
+ ////if (__has_delta_isChanged && this.manager) {
158
+ //// this.manager.setOption("hasDelta", this.__has_delta);
159
+ ////}
160
+ }
171
161
  /* --------------------------------- notify --------------------------------- */
172
- if (!(shouldNotify === true || shouldNotify === "auto" && isValueChanged)) {
162
+ if (!(shouldNotify === true || shouldNotify === "auto" && needsChange)) {
173
163
  _context.next = 13;
174
164
  break;
175
165
  }
176
166
  _context.next = 13;
177
167
  return this.notifyChanged("", key, value);
178
168
  case 13:
179
- return _context.abrupt("return", isValueChanged);
169
+ return _context.abrupt("return", needsChange);
180
170
  case 14:
181
171
  case "end":
182
172
  return _context.stop();
@@ -188,6 +178,21 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
188
178
  }
189
179
  return setValue;
190
180
  }())
181
+ }, {
182
+ key: "loadValues",
183
+ value: /* -------------------------------------------------------------------------- */
184
+ /* Load */
185
+ /* -------------------------------------------------------------------------- */
186
+ /**
187
+ * load all properties in `initObject` into the current object
188
+ * @param initObject
189
+ * @param fullUpdate
190
+ * @returns
191
+ */
192
+ function loadValues(initObject) {
193
+ var fullUpdate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
194
+ return SimpleObject.loadValues(this, initObject, fullUpdate);
195
+ }
191
196
  }, {
192
197
  key: "setTemp",
193
198
  value: function () {
@@ -596,7 +601,6 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
596
601
  while (1) switch (_context11.prev = _context11.next) {
597
602
  case 0:
598
603
  if (value === undefined && type == "") value = this.getValue(key);
599
- this.__changed = true;
600
604
  lc = "";
601
605
  if (type) lc += "$".concat(String(type), "$");
602
606
  if (subvalue) {
@@ -608,16 +612,16 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
608
612
  /* --------------------------- notify the manager --------------------------- */
609
613
  manager_class = this.manager;
610
614
  if (!(typeof (manager_class === null || manager_class === void 0 ? void 0 : manager_class.notifyChanged) === "function")) {
611
- _context11.next = 11;
615
+ _context11.next = 10;
612
616
  break;
613
617
  }
614
- _context11.next = 10;
618
+ _context11.next = 9;
615
619
  return manager_class.notifyChanged(type, key, value, subvalue);
616
- case 10:
620
+ case 9:
617
621
  return _context11.abrupt("return", _context11.sent);
618
- case 11:
622
+ case 10:
619
623
  return _context11.abrupt("return", false);
620
- case 12:
624
+ case 11:
621
625
  case "end":
622
626
  return _context11.stop();
623
627
  }
@@ -779,7 +783,7 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
779
783
  key: "clear_changes",
780
784
  value: function clear_changes() {
781
785
  this.__delta = {};
782
- this.__changed = false;
786
+ this.__has_delta = false;
783
787
  return true;
784
788
  }
785
789
  /**
@@ -811,7 +815,6 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
811
815
  get: function get() {
812
816
  return this.constructor["__db_name"] || this.constructor["__web_path"];
813
817
  }
814
- /* -------------------------------------------------------------------------- */
815
818
  }, {
816
819
  key: "isChanged",
817
820
  get: function get() {
@@ -819,13 +822,20 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
819
822
  ////const deltaIsBlank = object_isEmpty(this.__delta);
820
823
  ////if (!deltaIsBlank) return true; //delta is not blank, definitely changed
821
824
  ////if (this.__use_delta) return !deltaIsBlank; //trust the delta.
822
- if (this.__use_delta) return !(0, _object.object_isEmpty)(this.__delta);
823
- /* -------------------------------------------------------------------------- */
824
- /* check the properties one by one */
825
- /* -------------------------------------------------------------------------- */
825
+ if (this.__use_delta) {
826
+ return this.__has_delta;
827
+ ////for (const key in this.__delta) {
828
+ //// return true;
829
+ ////}
830
+ ////return false;
831
+ }
832
+ /* --------------------- check the properties one by one -------------------- */
826
833
  var orig = this.getOriginal();
827
834
  if (!orig) return false; //we dont know if anything has changed
828
- /* if object is not using delta mode, check changes by comparing changable fields with original object */
835
+ /**
836
+ * if object is not using delta mode,
837
+ * check changes by comparing changable fields with original object
838
+ */
829
839
  if (Array.isArray(this.__changeables)) {
830
840
  return this.__changeables.find(function (c) {
831
841
  return !(0, _object.object_equals)(_this3[c], orig[c]);
@@ -838,7 +848,6 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
838
848
  }
839
849
  return false;
840
850
  }
841
- return false;
842
851
  }
843
852
  }, {
844
853
  key: "isArchived",
@@ -969,7 +978,7 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
969
978
  /* -------------------------------------------------------------------------- */
970
979
  function () {
971
980
  var _event_run = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(eventName) {
972
- var _this$manager;
981
+ var _this$manager2;
973
982
  var _len2,
974
983
  params,
975
984
  _key2,
@@ -988,7 +997,7 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
988
997
  params[_key2 - 1] = _args14[_key2];
989
998
  }
990
999
  _context14.next = 6;
991
- return (_this$manager = this.manager).event_run.apply(_this$manager, [eventName].concat(params));
1000
+ return (_this$manager2 = this.manager).event_run.apply(_this$manager2, [eventName].concat(params));
992
1001
  case 6:
993
1002
  return _context14.abrupt("return", _context14.sent);
994
1003
  case 7:
@@ -1152,6 +1161,21 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
1152
1161
  /* statics */
1153
1162
  /* -------------------------------------------------------------------------- */
1154
1163
  }], [{
1164
+ key: "getValue",
1165
+ value: function getValue(o, key) {
1166
+ var original = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
1167
+ if (o == null) return undefined;
1168
+ if (o instanceof SimpleObject && typeof o.getValue === "function") return o.getValue(key, original);
1169
+ if (!original && o.__use_delta != false && _typeof(o.__delta) === "object" && key in o.__delta) {
1170
+ //@ts-ignore
1171
+ return o.__delta[key];
1172
+ }
1173
+ return o[key];
1174
+ }
1175
+ /* -------------------------------------------------------------------------- */
1176
+ /* setValue */
1177
+ /* -------------------------------------------------------------------------- */
1178
+ }, {
1155
1179
  key: "loadValues",
1156
1180
  value: function loadValues(obj, initObject) {
1157
1181
  var fullUpdate = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
@@ -1177,19 +1201,6 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
1177
1201
  }
1178
1202
  return true;
1179
1203
  }
1180
- /* -------------------------------------------------------------------------- */
1181
- }, {
1182
- key: "getValue",
1183
- value: function getValue(o, key) {
1184
- var original = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
1185
- if (o == null) return undefined;
1186
- if (o instanceof SimpleObject && typeof o.getValue === "function") return o.getValue(key, original);
1187
- if (!original && o.__use_delta != false && _typeof(o.__delta) === "object" && key in o.__delta) {
1188
- //@ts-ignore
1189
- return o.__delta[key];
1190
- }
1191
- return o[key];
1192
- }
1193
1204
  }, {
1194
1205
  key: "canChangeKey",
1195
1206
  value: function canChangeKey(object, key, options) {
@@ -1497,37 +1508,6 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
1497
1508
  }
1498
1509
  }]);
1499
1510
  }(_MapableObject2.MapableObject);
1500
- function _setSubProperty(key, subkey, value) {
1501
- var subobj = _assertClassBrand(_SimpleObject_brand, this, _getProperty).call(this, key);
1502
- //@ts-ignore
1503
- if (subobj == null || _typeof(subobj) !== "object") subobj = {};else subobj = _objectSpread({}, subobj); //make a clone so we dont update the original
1504
- subobj[subkey] = value;
1505
- _assertClassBrand(_SimpleObject_brand, this, _setProperty).call(this, key, subobj);
1506
- }
1507
- function _getSubProperty(key, subkey) {
1508
- var original = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
1509
- var subobj = _assertClassBrand(_SimpleObject_brand, this, _getProperty).call(this, key, original);
1510
- if (subobj == null || _typeof(subobj) !== "object") return undefined;
1511
- return subobj[subkey];
1512
- }
1513
- function _setProperty(key, value) {
1514
- if (!this.__use_delta) {
1515
- this[key] = value; //on noDelta mode, also update the obj
1516
- this.__delta[key] = value; //always update delta to keep track of changes
1517
- return true;
1518
- } else {
1519
- if (this[key] === value) {
1520
- /**
1521
- * We set something back to its original value so no need to save it as Delta
1522
- */
1523
- delete this.__delta[key];
1524
- return false;
1525
- } else {
1526
- this.__delta[key] = value; //always update delta to keep track of changes
1527
- return true;
1528
- }
1529
- }
1530
- }
1531
1511
  function _setDefaultProperty(key, value) {
1532
1512
  //@ts-ignore
1533
1513
  if (this[key] == undefined || this[key] === "" || this[key] === 0) {
@@ -1544,6 +1524,9 @@ function _setDefaultPropertyNow(key) {
1544
1524
  }
1545
1525
  return false;
1546
1526
  }
1527
+ /* -------------------------------------------------------------------------- */
1528
+ /* getProperty */
1529
+ /* -------------------------------------------------------------------------- */
1547
1530
  function _getProperty(key) {
1548
1531
  var original = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1549
1532
  //check if we should treat the prop as a function
@@ -1557,6 +1540,63 @@ function _getProperty(key) {
1557
1540
  if (use_orig) return this[key];
1558
1541
  return this.__delta[key];
1559
1542
  }
1543
+ function _setSubProperty(key, subkey, value) {
1544
+ var subobj = _assertClassBrand(_SimpleObject_brand, this, _getProperty).call(this, key);
1545
+ //@ts-ignore
1546
+ if (subobj == null || _typeof(subobj) !== "object") subobj = {};else subobj = _objectSpread({}, subobj); //make a clone so we dont update the original
1547
+ subobj[subkey] = value;
1548
+ _assertClassBrand(_SimpleObject_brand, this, _setProperty).call(this, key, subobj);
1549
+ }
1550
+ function _getSubProperty(key, subkey) {
1551
+ var original = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
1552
+ var subobj = _assertClassBrand(_SimpleObject_brand, this, _getProperty).call(this, key, original);
1553
+ if (subobj == null || _typeof(subobj) !== "object") return undefined;
1554
+ return subobj[subkey];
1555
+ }
1556
+ /**
1557
+ * update a property on this object by updating the `__delta`
1558
+ * or updating the object property directly depending on `__use_delta` setting
1559
+ *
1560
+ * @param key
1561
+ * @param value
1562
+ * @returns true if state of `__has_delta` is changed, false otherwise
1563
+ */
1564
+ function _setProperty(key, value) {
1565
+ var checkIsChanged = false;
1566
+ if (this.__use_delta) {
1567
+ if (this[key] === value) {
1568
+ /**
1569
+ * we set something back to its original value
1570
+ * no need to save it as delta
1571
+ */
1572
+ delete this.__delta[key];
1573
+ checkIsChanged = true; //check if we should set __has_delta to false
1574
+ } else {
1575
+ this.__delta[key] = value; //always update delta to keep track of changes
1576
+ }
1577
+ } else {
1578
+ this[key] = value; //on noDelta mode update the object itself
1579
+ this.__delta[key] = value; //always update delta to keep track of changes
1580
+ }
1581
+ if (checkIsChanged || this.__has_delta === false) {
1582
+ /**
1583
+ * if any key exists in the `__delta` then the object is changed
1584
+ */
1585
+ var next__has_delta = false;
1586
+ for (var _key4 in this.__delta) {
1587
+ next__has_delta = true;
1588
+ break;
1589
+ }
1590
+ var previous__has_delta = this.__has_delta;
1591
+ this.__has_delta = next__has_delta;
1592
+ /**
1593
+ * if the state of __has_delta is changed we return true
1594
+ * so we can run the needed events
1595
+ */
1596
+ return previous__has_delta != this.__has_delta;
1597
+ }
1598
+ return false;
1599
+ }
1560
1600
  function _setSaveResultObject(toObj) {
1561
1601
  if (toObj == null) toObj = null; //null or undefined
1562
1602
  this.__saveResultObject = toObj;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azrico/webobject",
3
- "version": "1.4.166",
3
+ "version": "1.4.168",
4
4
  "description": "Stateful object",
5
5
  "author": "Azrideus",
6
6
  "license": "MIT",