@azrico/webobject 1.4.166 → 1.4.167
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.
|
@@ -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
|
-
|
|
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 =
|
|
628
|
+
_context10.next = 6;
|
|
613
629
|
return this.event_run("on_option_change", key, value);
|
|
614
|
-
case
|
|
615
|
-
return _context10.abrupt("return",
|
|
616
|
-
case
|
|
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
|
-
|
|
712
|
-
return this.event_use("on_{change,save,load}",
|
|
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
|
|
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, "
|
|
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
|
-
|
|
143
|
-
|
|
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
|
-
|
|
164
|
-
|
|
145
|
+
old_value = this.getValue(key);
|
|
146
|
+
needsChange = !(0, _object.object_equals)(old_value, value, {
|
|
165
147
|
strictArrayCheck: true,
|
|
166
148
|
ignoredStartingWords: "_"
|
|
167
|
-
})
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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" &&
|
|
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",
|
|
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 =
|
|
615
|
+
_context11.next = 10;
|
|
612
616
|
break;
|
|
613
617
|
}
|
|
614
|
-
_context11.next =
|
|
618
|
+
_context11.next = 9;
|
|
615
619
|
return manager_class.notifyChanged(type, key, value, subvalue);
|
|
616
|
-
case
|
|
620
|
+
case 9:
|
|
617
621
|
return _context11.abrupt("return", _context11.sent);
|
|
618
|
-
case
|
|
622
|
+
case 10:
|
|
619
623
|
return _context11.abrupt("return", false);
|
|
620
|
-
case
|
|
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.
|
|
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)
|
|
823
|
-
|
|
824
|
-
|
|
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
|
-
|
|
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$
|
|
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$
|
|
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;
|