@azrico/webobject 1.3.26 → 1.4.1

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
@@ -5,48 +5,5 @@
5
5
  ## Install
6
6
 
7
7
  ```bash
8
- npm install --save deus-object
8
+ yarn add @azrico/webobject
9
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/)
@@ -14,7 +14,7 @@ export declare class WebObjectManager<T extends WebObject> extends ObjectManager
14
14
  * @param key name of the option
15
15
  * @returns value of the option
16
16
  */
17
- useOption(key: string): Promise<any>;
17
+ useOption(key: string): any;
18
18
  /**
19
19
  * Update meta value of this object , meta data is stored in meta_data variable
20
20
  * @param key
@@ -87,26 +87,12 @@ var WebObjectManager = /*#__PURE__*/function (_ObjectManager) {
87
87
  */
88
88
  _createClass(WebObjectManager, [{
89
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
- }()
90
+ value: function useOption(key) {
91
+ var _this2 = this;
92
+ return this.event_use("on_option_change", function () {
93
+ return Boolean(_this2.getOption(key));
94
+ }, [key], false);
95
+ }
110
96
  /* -------------------------------------------------------------------------- */
111
97
  /* Meta data */
112
98
  /* -------------------------------------------------------------------------- */
@@ -142,27 +128,27 @@ var WebObjectManager = /*#__PURE__*/function (_ObjectManager) {
142
128
  }, {
143
129
  key: "get_deltaObject",
144
130
  value: function () {
145
- var _get_deltaObject = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
131
+ var _get_deltaObject = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
146
132
  var _this$obj4;
147
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
148
- while (1) switch (_context3.prev = _context3.next) {
133
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
134
+ while (1) switch (_context2.prev = _context2.next) {
149
135
  case 0:
150
- _context3.next = 2;
136
+ _context2.next = 2;
151
137
  return (_this$obj4 = this.obj) === null || _this$obj4 === void 0 ? void 0 : _this$obj4.get_deltaObject();
152
138
  case 2:
153
- _context3.t0 = _context3.sent;
154
- if (_context3.t0) {
155
- _context3.next = 5;
139
+ _context2.t0 = _context2.sent;
140
+ if (_context2.t0) {
141
+ _context2.next = 5;
156
142
  break;
157
143
  }
158
- _context3.t0 = {};
144
+ _context2.t0 = {};
159
145
  case 5:
160
- return _context3.abrupt("return", _context3.t0);
146
+ return _context2.abrupt("return", _context2.t0);
161
147
  case 6:
162
148
  case "end":
163
- return _context3.stop();
149
+ return _context2.stop();
164
150
  }
165
- }, _callee3, this);
151
+ }, _callee2, this);
166
152
  }));
167
153
  function get_deltaObject() {
168
154
  return _get_deltaObject.apply(this, arguments);
@@ -172,27 +158,27 @@ var WebObjectManager = /*#__PURE__*/function (_ObjectManager) {
172
158
  }, {
173
159
  key: "Save",
174
160
  value: function () {
175
- var _Save = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
161
+ var _Save = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
176
162
  var _this$obj5;
177
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
178
- while (1) switch (_context4.prev = _context4.next) {
163
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
164
+ while (1) switch (_context3.prev = _context3.next) {
179
165
  case 0:
180
- _context4.next = 2;
166
+ _context3.next = 2;
181
167
  return (_this$obj5 = this.obj) === null || _this$obj5 === void 0 ? void 0 : _this$obj5.Save();
182
168
  case 2:
183
- _context4.t0 = _context4.sent;
184
- if (_context4.t0) {
185
- _context4.next = 5;
169
+ _context3.t0 = _context3.sent;
170
+ if (_context3.t0) {
171
+ _context3.next = 5;
186
172
  break;
187
173
  }
188
- _context4.t0 = false;
174
+ _context3.t0 = false;
189
175
  case 5:
190
- return _context4.abrupt("return", _context4.t0);
176
+ return _context3.abrupt("return", _context3.t0);
191
177
  case 6:
192
178
  case "end":
193
- return _context4.stop();
179
+ return _context3.stop();
194
180
  }
195
- }, _callee4, this);
181
+ }, _callee3, this);
196
182
  }));
197
183
  function Save() {
198
184
  return _Save.apply(this, arguments);
@@ -202,18 +188,18 @@ var WebObjectManager = /*#__PURE__*/function (_ObjectManager) {
202
188
  }, {
203
189
  key: "Load",
204
190
  value: function () {
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) {
191
+ var _Load = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(search) {
192
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
193
+ while (1) switch (_context4.prev = _context4.next) {
208
194
  case 0:
209
195
  throw Error("load not implented");
210
196
  case 1:
211
197
  case "end":
212
- return _context5.stop();
198
+ return _context4.stop();
213
199
  }
214
- }, _callee5);
200
+ }, _callee4);
215
201
  }));
216
- function Load(_x2) {
202
+ function Load(_x) {
217
203
  return _Load.apply(this, arguments);
218
204
  }
219
205
  return Load;
@@ -249,32 +235,32 @@ var WebObjectManager = /*#__PURE__*/function (_ObjectManager) {
249
235
  }, {
250
236
  key: "onNew",
251
237
  value: function () {
252
- var _onNew = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
238
+ var _onNew = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
253
239
  var _this$obj8;
254
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
255
- while (1) switch (_context6.prev = _context6.next) {
240
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
241
+ while (1) switch (_context5.prev = _context5.next) {
256
242
  case 0:
257
243
  if (this.canModify) {
258
244
  (_this$obj8 = this.obj) === null || _this$obj8 === void 0 ? void 0 : _this$obj8.setOriginal();
259
245
  }
260
- _context6.next = 3;
246
+ _context5.next = 3;
261
247
  return this.event_run("on_new");
262
248
  case 3:
263
- _context6.next = 5;
249
+ _context5.next = 5;
264
250
  return this.event_run("on_change", true);
265
251
  case 5:
266
- _context6.next = 7;
252
+ _context5.next = 7;
267
253
  return this.event_run("on_after_new");
268
254
  case 7:
269
- _context6.next = 9;
255
+ _context5.next = 9;
270
256
  return Promise.resolve(true);
271
257
  case 9:
272
- return _context6.abrupt("return", _context6.sent);
258
+ return _context5.abrupt("return", _context5.sent);
273
259
  case 10:
274
260
  case "end":
275
- return _context6.stop();
261
+ return _context5.stop();
276
262
  }
277
- }, _callee6, this);
263
+ }, _callee5, this);
278
264
  }));
279
265
  function onNew() {
280
266
  return _onNew.apply(this, arguments);
@@ -289,28 +275,28 @@ var WebObjectManager = /*#__PURE__*/function (_ObjectManager) {
289
275
  }, {
290
276
  key: "onDelete",
291
277
  value: function () {
292
- var _onDelete = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
293
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
294
- while (1) switch (_context7.prev = _context7.next) {
278
+ var _onDelete = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
279
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
280
+ while (1) switch (_context6.prev = _context6.next) {
295
281
  case 0:
296
282
  if (this.obj) {
297
283
  this.obj.isDeleted = true;
298
284
  }
299
- _context7.next = 3;
285
+ _context6.next = 3;
300
286
  return this.event_run("on_delete");
301
287
  case 3:
302
- _context7.next = 5;
288
+ _context6.next = 5;
303
289
  return this.event_run("on_after_delete");
304
290
  case 5:
305
- _context7.next = 7;
291
+ _context6.next = 7;
306
292
  return Promise.resolve(true);
307
293
  case 7:
308
- return _context7.abrupt("return", _context7.sent);
294
+ return _context6.abrupt("return", _context6.sent);
309
295
  case 8:
310
296
  case "end":
311
- return _context7.stop();
297
+ return _context6.stop();
312
298
  }
313
- }, _callee7, this);
299
+ }, _callee6, this);
314
300
  }));
315
301
  function onDelete() {
316
302
  return _onDelete.apply(this, arguments);
@@ -325,35 +311,35 @@ var WebObjectManager = /*#__PURE__*/function (_ObjectManager) {
325
311
  }, {
326
312
  key: "onLoad",
327
313
  value: function () {
328
- var _onLoad = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
329
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
330
- while (1) switch (_context8.prev = _context8.next) {
314
+ var _onLoad = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
315
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
316
+ while (1) switch (_context7.prev = _context7.next) {
331
317
  case 0:
332
318
  if (this.canModify && this.obj) {
333
319
  this.obj.isDeleted = false;
334
320
  this.obj.setOriginal();
335
321
  }
336
- _context8.next = 3;
322
+ _context7.next = 3;
337
323
  return this.event_run("on_load");
338
324
  case 3:
339
- _context8.next = 5;
325
+ _context7.next = 5;
340
326
  return this.event_run("on_change", true);
341
327
  case 5:
342
- _context8.next = 7;
328
+ _context7.next = 7;
343
329
  return this.event_run("on_after_load");
344
330
  case 7:
345
- _context8.next = 9;
331
+ _context7.next = 9;
346
332
  return this.event_run("on_load_finished");
347
333
  case 9:
348
- _context8.next = 11;
334
+ _context7.next = 11;
349
335
  return Promise.resolve(true);
350
336
  case 11:
351
- return _context8.abrupt("return", _context8.sent);
337
+ return _context7.abrupt("return", _context7.sent);
352
338
  case 12:
353
339
  case "end":
354
- return _context8.stop();
340
+ return _context7.stop();
355
341
  }
356
- }, _callee8, this);
342
+ }, _callee7, this);
357
343
  }));
358
344
  function onLoad() {
359
345
  return _onLoad.apply(this, arguments);
@@ -368,31 +354,31 @@ var WebObjectManager = /*#__PURE__*/function (_ObjectManager) {
368
354
  }, {
369
355
  key: "onSave",
370
356
  value: function () {
371
- var _onSave = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
372
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
373
- while (1) switch (_context9.prev = _context9.next) {
357
+ var _onSave = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
358
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
359
+ while (1) switch (_context8.prev = _context8.next) {
374
360
  case 0:
375
- _context9.next = 2;
361
+ _context8.next = 2;
376
362
  return this.event_run("on_save");
377
363
  case 2:
378
- _context9.next = 4;
364
+ _context8.next = 4;
379
365
  return this.event_run("on_change", true);
380
366
  case 4:
381
- _context9.next = 6;
367
+ _context8.next = 6;
382
368
  return this.event_run("on_after_save");
383
369
  case 6:
384
- _context9.next = 8;
370
+ _context8.next = 8;
385
371
  return this.event_run("on_save_finished");
386
372
  case 8:
387
- _context9.next = 10;
373
+ _context8.next = 10;
388
374
  return Promise.resolve(true);
389
375
  case 10:
390
- return _context9.abrupt("return", _context9.sent);
376
+ return _context8.abrupt("return", _context8.sent);
391
377
  case 11:
392
378
  case "end":
393
- return _context9.stop();
379
+ return _context8.stop();
394
380
  }
395
- }, _callee9, this);
381
+ }, _callee8, this);
396
382
  }));
397
383
  function onSave() {
398
384
  return _onSave.apply(this, arguments);
@@ -140,6 +140,10 @@ export declare class SimpleObject extends MapableObject {
140
140
  static getIndexOrID(o: any): number;
141
141
  static getIndex(o: any): number;
142
142
  static getID(o: any): string;
143
+ event_run(eventName: string, ...params: any): Promise<any[] | undefined>;
144
+ event_use(name: string, runEvent: (...inputdata: any) => any, onlyOn?: any, runOnce?: boolean): any;
145
+ event_remove(name: string, uname: string): boolean | undefined;
146
+ event_add(name: string, uname: string, runEvent: (...inputdata: any) => any, onlyOn?: any, runOnce?: boolean): Promise<void>;
143
147
  getOriginal(): this | undefined;
144
148
  setOriginal(toObj?: null | 0 | any): this | undefined;
145
149
  static setOriginal<T>(obj: T, toObj?: null | 0 | any): T | undefined;
@@ -646,11 +646,104 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
646
646
  return SimpleObject.getID(this);
647
647
  }
648
648
  }, {
649
- key: "getOriginal",
650
- value: /* -------------------------------------------------------------------------- */
649
+ key: "event_run",
650
+ value:
651
+ /* -------------------------------------------------------------------------- */
652
+ /* Events */
653
+ /* -------------------------------------------------------------------------- */
654
+ function () {
655
+ var _event_run = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(eventName) {
656
+ var _this$manager;
657
+ var _len,
658
+ params,
659
+ _key,
660
+ _args7 = arguments;
661
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
662
+ while (1) switch (_context7.prev = _context7.next) {
663
+ case 0:
664
+ if (this.manager) {
665
+ _context7.next = 3;
666
+ break;
667
+ }
668
+ console.error("you cant use events if your object has no manager");
669
+ return _context7.abrupt("return");
670
+ case 3:
671
+ for (_len = _args7.length, params = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
672
+ params[_key - 1] = _args7[_key];
673
+ }
674
+ _context7.next = 6;
675
+ return (_this$manager = this.manager).event_run.apply(_this$manager, [eventName].concat(params));
676
+ case 6:
677
+ return _context7.abrupt("return", _context7.sent);
678
+ case 7:
679
+ case "end":
680
+ return _context7.stop();
681
+ }
682
+ }, _callee7, this);
683
+ }));
684
+ function event_run(_x13) {
685
+ return _event_run.apply(this, arguments);
686
+ }
687
+ return event_run;
688
+ }()
689
+ }, {
690
+ key: "event_use",
691
+ value: function event_use(name, runEvent) {
692
+ var onlyOn = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
693
+ var runOnce = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
694
+ if (!this.manager) {
695
+ console.error("you cant use events if your object has no manager");
696
+ return;
697
+ }
698
+ return this.manager.event_use(name, runEvent, onlyOn, runOnce);
699
+ }
700
+ }, {
701
+ key: "event_remove",
702
+ value: function event_remove(name, uname) {
703
+ if (!this.manager) {
704
+ console.error("you cant use events if your object has no manager");
705
+ return;
706
+ }
707
+ return this.manager.event_remove(name, uname);
708
+ }
709
+ }, {
710
+ key: "event_add",
711
+ value: function () {
712
+ var _event_add = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(name, uname, runEvent) {
713
+ var onlyOn,
714
+ runOnce,
715
+ _args8 = arguments;
716
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
717
+ while (1) switch (_context8.prev = _context8.next) {
718
+ case 0:
719
+ onlyOn = _args8.length > 3 && _args8[3] !== undefined ? _args8[3] : null;
720
+ runOnce = _args8.length > 4 && _args8[4] !== undefined ? _args8[4] : false;
721
+ if (this.manager) {
722
+ _context8.next = 5;
723
+ break;
724
+ }
725
+ console.error("you cant use events if your object has no manager");
726
+ return _context8.abrupt("return");
727
+ case 5:
728
+ _context8.next = 7;
729
+ return this.manager.event_add(name, uname, runEvent, onlyOn, runOnce);
730
+ case 7:
731
+ case "end":
732
+ return _context8.stop();
733
+ }
734
+ }, _callee8, this);
735
+ }));
736
+ function event_add(_x14, _x15, _x16) {
737
+ return _event_add.apply(this, arguments);
738
+ }
739
+ return event_add;
740
+ }()
741
+ /* -------------------------------------------------------------------------- */
651
742
  /* Original */
652
743
  /* -------------------------------------------------------------------------- */
653
- function getOriginal() {
744
+ }, {
745
+ key: "getOriginal",
746
+ value: function getOriginal() {
654
747
  return this.__originalobject || undefined;
655
748
  }
656
749
  }, {
@@ -722,10 +815,10 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
722
815
  delete obj[key];
723
816
  }
724
817
  } else if (_typeof(initObject) == "object") {
725
- for (var _key in initObject) {
726
- if (_key.startsWith("__")) continue;
727
- if (fullUpdate || Object.prototype.hasOwnProperty.call(obj, _key)) {
728
- obj[_key] = initObject[_key];
818
+ for (var _key2 in initObject) {
819
+ if (_key2.startsWith("__")) continue;
820
+ if (fullUpdate || Object.prototype.hasOwnProperty.call(obj, _key2)) {
821
+ obj[_key2] = initObject[_key2];
729
822
  }
730
823
  }
731
824
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azrico/webobject",
3
- "version": "1.3.26",
3
+ "version": "1.4.1",
4
4
  "description": "Stateful object",
5
5
  "author": "Azrideus",
6
6
  "license": "MIT",