@azrico/webobject 1.3.19 → 1.3.21

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.
package/README.md CHANGED
@@ -1,52 +1,52 @@
1
- # deus-object
2
-
3
- > Some useful object functions
4
-
5
- ## Install
6
-
7
- ```bash
8
- npm install --save deus-object
9
- ```
10
-
11
- ## Functions
12
-
13
- ```js
14
- object_clone(object);
15
- object_first(object);
16
- object_update(a, b);
17
- object_delta(a, b);
18
- object_has_delta(object);
19
- object_equals(a, b);
20
- isEmpty(object);
21
- ```
22
-
23
- ## Usage
24
-
25
- ```js
26
- import React, { Component } from 'react'
27
- import { View } from 'react-native'
28
- import FuncObject from 'deus-object'
29
-
30
- class Example extends Component {
31
-
32
- let eq1=FuncObject.object_equals({a:"b"},{a:"b"});//true
33
- let eq2=FuncObject.object_equals({a:"b"},{a:"c"});//false
34
-
35
- let ie1=FuncObject.isEmpty({}); //true
36
- let ie2=FuncObject.isEmpty([]); //true
37
- let ie3=FuncObject.isEmpty(null);//true
38
- let ie4=FuncObject.isEmpty({test:"a"});//false
39
-
40
- let if1=FuncObject.object_first({a:"a",b:"b",c:"c"});// a:"a"
41
- let if2=FuncObject.object_first([1,2,3,4]);//1
42
-
43
-
44
- render() {
45
- return <View></View>
46
- }
47
- }
48
- ```
49
-
50
- ## License
51
-
52
- MIT © [](https://github.com/)
1
+ # deus-object
2
+
3
+ > Some useful object functions
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install --save deus-object
9
+ ```
10
+
11
+ ## Functions
12
+
13
+ ```js
14
+ object_clone(object);
15
+ object_first(object);
16
+ object_update(a, b);
17
+ object_delta(a, b);
18
+ object_has_delta(object);
19
+ object_equals(a, b);
20
+ isEmpty(object);
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ ```js
26
+ import React, { Component } from 'react'
27
+ import { View } from 'react-native'
28
+ import FuncObject from 'deus-object'
29
+
30
+ class Example extends Component {
31
+
32
+ let eq1=FuncObject.object_equals({a:"b"},{a:"b"});//true
33
+ let eq2=FuncObject.object_equals({a:"b"},{a:"c"});//false
34
+
35
+ let ie1=FuncObject.isEmpty({}); //true
36
+ let ie2=FuncObject.isEmpty([]); //true
37
+ let ie3=FuncObject.isEmpty(null);//true
38
+ let ie4=FuncObject.isEmpty({test:"a"});//false
39
+
40
+ let if1=FuncObject.object_first({a:"a",b:"b",c:"c"});// a:"a"
41
+ let if2=FuncObject.object_first([1,2,3,4]);//1
42
+
43
+
44
+ render() {
45
+ return <View></View>
46
+ }
47
+ }
48
+ ```
49
+
50
+ ## License
51
+
52
+ MIT © [](https://github.com/)
@@ -9,6 +9,12 @@ export declare class WebObjectManager<T extends WebObject> extends ObjectManager
9
9
  static readonly __web_type: string;
10
10
  static readonly __save_message: boolean;
11
11
  constructor();
12
+ /**
13
+ * use an option and detect its changes in real time. similar to recat state
14
+ * @param key name of the option
15
+ * @returns value of the option
16
+ */
17
+ useOption(key: string): Promise<any>;
12
18
  /**
13
19
  * Update meta value of this object , meta data is stored in meta_data variable
14
20
  * @param key
@@ -30,8 +30,6 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
30
30
  var WebObjectManager = /*#__PURE__*/function (_ObjectManager) {
31
31
  _inherits(WebObjectManager, _ObjectManager);
32
32
  var _super = _createSuper(WebObjectManager);
33
- //we use this as backup
34
-
35
33
  /* -------------------------------------------------------------------------- */
36
34
  function WebObjectManager() {
37
35
  var _this;
@@ -80,17 +78,47 @@ var WebObjectManager = /*#__PURE__*/function (_ObjectManager) {
80
78
  return _this;
81
79
  }
82
80
  /* -------------------------------------------------------------------------- */
83
- /* Meta data */
81
+ /* Options */
84
82
  /* -------------------------------------------------------------------------- */
85
83
  /**
86
- * Update meta value of this object , meta data is stored in meta_data variable
87
- * @param key
88
- * @param value
89
- * @param createIfNotExists should we create a new meta if key does not exist
90
- * @param sendChange
91
- * @returns
84
+ * use an option and detect its changes in real time. similar to recat state
85
+ * @param key name of the option
86
+ * @returns value of the option
92
87
  */
93
88
  _createClass(WebObjectManager, [{
89
+ key: "useOption",
90
+ value: function () {
91
+ var _useOption = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(key) {
92
+ var _this2 = this;
93
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
94
+ while (1) switch (_context2.prev = _context2.next) {
95
+ case 0:
96
+ return _context2.abrupt("return", this.event_use("on_option_change", function () {
97
+ return Boolean(_this2.getOption(key));
98
+ }, [key], false));
99
+ case 1:
100
+ case "end":
101
+ return _context2.stop();
102
+ }
103
+ }, _callee2, this);
104
+ }));
105
+ function useOption(_x) {
106
+ return _useOption.apply(this, arguments);
107
+ }
108
+ return useOption;
109
+ }()
110
+ /* -------------------------------------------------------------------------- */
111
+ /* Meta data */
112
+ /* -------------------------------------------------------------------------- */
113
+ /**
114
+ * Update meta value of this object , meta data is stored in meta_data variable
115
+ * @param key
116
+ * @param value
117
+ * @param createIfNotExists should we create a new meta if key does not exist
118
+ * @param sendChange
119
+ * @returns
120
+ */
121
+ }, {
94
122
  key: "setMetaValue",
95
123
  value: function setMetaValue(key, value) {
96
124
  var _this$obj;
@@ -114,27 +142,27 @@ var WebObjectManager = /*#__PURE__*/function (_ObjectManager) {
114
142
  }, {
115
143
  key: "get_deltaObject",
116
144
  value: function () {
117
- var _get_deltaObject = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
145
+ var _get_deltaObject = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
118
146
  var _this$obj4;
119
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
120
- while (1) switch (_context2.prev = _context2.next) {
147
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
148
+ while (1) switch (_context3.prev = _context3.next) {
121
149
  case 0:
122
- _context2.next = 2;
150
+ _context3.next = 2;
123
151
  return (_this$obj4 = this.obj) === null || _this$obj4 === void 0 ? void 0 : _this$obj4.get_deltaObject();
124
152
  case 2:
125
- _context2.t0 = _context2.sent;
126
- if (_context2.t0) {
127
- _context2.next = 5;
153
+ _context3.t0 = _context3.sent;
154
+ if (_context3.t0) {
155
+ _context3.next = 5;
128
156
  break;
129
157
  }
130
- _context2.t0 = {};
158
+ _context3.t0 = {};
131
159
  case 5:
132
- return _context2.abrupt("return", _context2.t0);
160
+ return _context3.abrupt("return", _context3.t0);
133
161
  case 6:
134
162
  case "end":
135
- return _context2.stop();
163
+ return _context3.stop();
136
164
  }
137
- }, _callee2, this);
165
+ }, _callee3, this);
138
166
  }));
139
167
  function get_deltaObject() {
140
168
  return _get_deltaObject.apply(this, arguments);
@@ -144,27 +172,27 @@ var WebObjectManager = /*#__PURE__*/function (_ObjectManager) {
144
172
  }, {
145
173
  key: "Save",
146
174
  value: function () {
147
- var _Save = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
175
+ var _Save = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
148
176
  var _this$obj5;
149
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
150
- while (1) switch (_context3.prev = _context3.next) {
177
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
178
+ while (1) switch (_context4.prev = _context4.next) {
151
179
  case 0:
152
- _context3.next = 2;
180
+ _context4.next = 2;
153
181
  return (_this$obj5 = this.obj) === null || _this$obj5 === void 0 ? void 0 : _this$obj5.Save();
154
182
  case 2:
155
- _context3.t0 = _context3.sent;
156
- if (_context3.t0) {
157
- _context3.next = 5;
183
+ _context4.t0 = _context4.sent;
184
+ if (_context4.t0) {
185
+ _context4.next = 5;
158
186
  break;
159
187
  }
160
- _context3.t0 = false;
188
+ _context4.t0 = false;
161
189
  case 5:
162
- return _context3.abrupt("return", _context3.t0);
190
+ return _context4.abrupt("return", _context4.t0);
163
191
  case 6:
164
192
  case "end":
165
- return _context3.stop();
193
+ return _context4.stop();
166
194
  }
167
- }, _callee3, this);
195
+ }, _callee4, this);
168
196
  }));
169
197
  function Save() {
170
198
  return _Save.apply(this, arguments);
@@ -174,18 +202,18 @@ var WebObjectManager = /*#__PURE__*/function (_ObjectManager) {
174
202
  }, {
175
203
  key: "Load",
176
204
  value: function () {
177
- var _Load = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(search) {
178
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
179
- while (1) switch (_context4.prev = _context4.next) {
205
+ var _Load = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(search) {
206
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
207
+ while (1) switch (_context5.prev = _context5.next) {
180
208
  case 0:
181
209
  throw Error("load not implented");
182
210
  case 1:
183
211
  case "end":
184
- return _context4.stop();
212
+ return _context5.stop();
185
213
  }
186
- }, _callee4);
214
+ }, _callee5);
187
215
  }));
188
- function Load(_x) {
216
+ function Load(_x2) {
189
217
  return _Load.apply(this, arguments);
190
218
  }
191
219
  return Load;
@@ -221,32 +249,32 @@ var WebObjectManager = /*#__PURE__*/function (_ObjectManager) {
221
249
  }, {
222
250
  key: "onNew",
223
251
  value: function () {
224
- var _onNew = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
252
+ var _onNew = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
225
253
  var _this$obj8;
226
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
227
- while (1) switch (_context5.prev = _context5.next) {
254
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
255
+ while (1) switch (_context6.prev = _context6.next) {
228
256
  case 0:
229
257
  if (this.canModify) {
230
258
  (_this$obj8 = this.obj) === null || _this$obj8 === void 0 ? void 0 : _this$obj8.setOriginal();
231
259
  }
232
- _context5.next = 3;
260
+ _context6.next = 3;
233
261
  return this.event_run("on_new");
234
262
  case 3:
235
- _context5.next = 5;
263
+ _context6.next = 5;
236
264
  return this.event_run("on_change", true);
237
265
  case 5:
238
- _context5.next = 7;
266
+ _context6.next = 7;
239
267
  return this.event_run("on_after_new");
240
268
  case 7:
241
- _context5.next = 9;
269
+ _context6.next = 9;
242
270
  return Promise.resolve(true);
243
271
  case 9:
244
- return _context5.abrupt("return", _context5.sent);
272
+ return _context6.abrupt("return", _context6.sent);
245
273
  case 10:
246
274
  case "end":
247
- return _context5.stop();
275
+ return _context6.stop();
248
276
  }
249
- }, _callee5, this);
277
+ }, _callee6, this);
250
278
  }));
251
279
  function onNew() {
252
280
  return _onNew.apply(this, arguments);
@@ -261,28 +289,28 @@ var WebObjectManager = /*#__PURE__*/function (_ObjectManager) {
261
289
  }, {
262
290
  key: "onDelete",
263
291
  value: function () {
264
- var _onDelete = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
265
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
266
- while (1) switch (_context6.prev = _context6.next) {
292
+ var _onDelete = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
293
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
294
+ while (1) switch (_context7.prev = _context7.next) {
267
295
  case 0:
268
296
  if (this.obj) {
269
297
  this.obj.isDeleted = true;
270
298
  }
271
- _context6.next = 3;
299
+ _context7.next = 3;
272
300
  return this.event_run("on_delete");
273
301
  case 3:
274
- _context6.next = 5;
302
+ _context7.next = 5;
275
303
  return this.event_run("on_after_delete");
276
304
  case 5:
277
- _context6.next = 7;
305
+ _context7.next = 7;
278
306
  return Promise.resolve(true);
279
307
  case 7:
280
- return _context6.abrupt("return", _context6.sent);
308
+ return _context7.abrupt("return", _context7.sent);
281
309
  case 8:
282
310
  case "end":
283
- return _context6.stop();
311
+ return _context7.stop();
284
312
  }
285
- }, _callee6, this);
313
+ }, _callee7, this);
286
314
  }));
287
315
  function onDelete() {
288
316
  return _onDelete.apply(this, arguments);
@@ -297,35 +325,35 @@ var WebObjectManager = /*#__PURE__*/function (_ObjectManager) {
297
325
  }, {
298
326
  key: "onLoad",
299
327
  value: function () {
300
- var _onLoad = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
301
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
302
- while (1) switch (_context7.prev = _context7.next) {
328
+ var _onLoad = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
329
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
330
+ while (1) switch (_context8.prev = _context8.next) {
303
331
  case 0:
304
332
  if (this.canModify && this.obj) {
305
333
  this.obj.isDeleted = false;
306
334
  this.obj.setOriginal();
307
335
  }
308
- _context7.next = 3;
336
+ _context8.next = 3;
309
337
  return this.event_run("on_load");
310
338
  case 3:
311
- _context7.next = 5;
339
+ _context8.next = 5;
312
340
  return this.event_run("on_change", true);
313
341
  case 5:
314
- _context7.next = 7;
342
+ _context8.next = 7;
315
343
  return this.event_run("on_after_load");
316
344
  case 7:
317
- _context7.next = 9;
345
+ _context8.next = 9;
318
346
  return this.event_run("on_load_finished");
319
347
  case 9:
320
- _context7.next = 11;
348
+ _context8.next = 11;
321
349
  return Promise.resolve(true);
322
350
  case 11:
323
- return _context7.abrupt("return", _context7.sent);
351
+ return _context8.abrupt("return", _context8.sent);
324
352
  case 12:
325
353
  case "end":
326
- return _context7.stop();
354
+ return _context8.stop();
327
355
  }
328
- }, _callee7, this);
356
+ }, _callee8, this);
329
357
  }));
330
358
  function onLoad() {
331
359
  return _onLoad.apply(this, arguments);
@@ -340,31 +368,31 @@ var WebObjectManager = /*#__PURE__*/function (_ObjectManager) {
340
368
  }, {
341
369
  key: "onSave",
342
370
  value: function () {
343
- var _onSave = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
344
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
345
- while (1) switch (_context8.prev = _context8.next) {
371
+ var _onSave = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
372
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
373
+ while (1) switch (_context9.prev = _context9.next) {
346
374
  case 0:
347
- _context8.next = 2;
375
+ _context9.next = 2;
348
376
  return this.event_run("on_save");
349
377
  case 2:
350
- _context8.next = 4;
378
+ _context9.next = 4;
351
379
  return this.event_run("on_change", true);
352
380
  case 4:
353
- _context8.next = 6;
381
+ _context9.next = 6;
354
382
  return this.event_run("on_after_save");
355
383
  case 6:
356
- _context8.next = 8;
384
+ _context9.next = 8;
357
385
  return this.event_run("on_save_finished");
358
386
  case 8:
359
- _context8.next = 10;
387
+ _context9.next = 10;
360
388
  return Promise.resolve(true);
361
389
  case 10:
362
- return _context8.abrupt("return", _context8.sent);
390
+ return _context9.abrupt("return", _context9.sent);
363
391
  case 11:
364
392
  case "end":
365
- return _context8.stop();
393
+ return _context9.stop();
366
394
  }
367
- }, _callee8, this);
395
+ }, _callee9, this);
368
396
  }));
369
397
  function onSave() {
370
398
  return _onSave.apply(this, arguments);
@@ -375,6 +403,7 @@ var WebObjectManager = /*#__PURE__*/function (_ObjectManager) {
375
403
  return WebObjectManager;
376
404
  }(_ObjectManager2["default"]);
377
405
  exports.WebObjectManager = WebObjectManager;
406
+ //we use this as backup
378
407
  _defineProperty(WebObjectManager, "__web_path", "");
379
408
  _defineProperty(WebObjectManager, "__web_type", "");
380
409
  _defineProperty(WebObjectManager, "__save_message", true);
@@ -12,15 +12,14 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
12
12
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
13
13
  function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
14
14
  var ObjectArray = /*#__PURE__*/function () {
15
- /* -------------------------------------------------------------------------- */
16
- /* Values */
17
- /* -------------------------------------------------------------------------- */
18
-
19
15
  /* -------------------------------------------------------------------------- */
20
16
  /* Base */
21
17
  /* -------------------------------------------------------------------------- */
22
18
  function ObjectArray(initObject, mapto_type) {
23
19
  _classCallCheck(this, ObjectArray);
20
+ /* -------------------------------------------------------------------------- */
21
+ /* Values */
22
+ /* -------------------------------------------------------------------------- */
24
23
  _defineProperty(this, "objArray", []);
25
24
  this.setObjects(initObject, mapto_type);
26
25
  }
@@ -305,9 +305,6 @@ var ObjectManager = /*#__PURE__*/function () {
305
305
  return ((_this$obj10 = this.obj) === null || _this$obj10 === void 0 ? void 0 : _this$obj10.getID()) || "";
306
306
  }
307
307
  /* -------------------------------------------------------------------------- */
308
- /* Getters */
309
- /* -------------------------------------------------------------------------- */
310
- /* -------------------------------------------------------------------------- */
311
308
  /* Events */
312
309
  /* -------------------------------------------------------------------------- */
313
310
  }, {
@@ -114,14 +114,7 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
114
114
  }
115
115
  _createClass(SimpleObject, [{
116
116
  key: "_static",
117
- value:
118
- //these properties should not be changed and are usually set by server
119
-
120
- //these properties can be directly changed and are included in deltaObject
121
-
122
- //these properties usually are not directly changed and sometimes are included in deltaObject
123
-
124
- function _static() {
117
+ value: function _static() {
125
118
  return this.constructor;
126
119
  }
127
120
  }, {
@@ -1013,8 +1006,11 @@ function _setSaveResultObject2(toObj) {
1013
1006
  this.__saveResultObject = toObj;
1014
1007
  }
1015
1008
  _defineProperty(SimpleObject, "__cache_name", void 0);
1009
+ //these properties should not be changed and are usually set by server
1016
1010
  _defineProperty(SimpleObject, "__unchangeables", void 0);
1011
+ //these properties can be directly changed and are included in deltaObject
1017
1012
  _defineProperty(SimpleObject, "__changeables", void 0);
1013
+ //these properties usually are not directly changed and sometimes are included in deltaObject
1018
1014
  _defineProperty(SimpleObject, "__extraProperties", void 0);
1019
1015
  _defineProperty(SimpleObject, "__use_delta", true);
1020
1016
  var _default = SimpleObject;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azrico/webobject",
3
- "version": "1.3.19",
3
+ "version": "1.3.21",
4
4
  "description": "Stateful object",
5
5
  "author": "Azrideus",
6
6
  "license": "MIT",