@azrico/webobject 1.3.24 → 1.4.0

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/)
@@ -10,7 +10,7 @@ export declare class ObjectManager<ObjType extends SimpleObject> {
10
10
  __sendEvents: boolean;
11
11
  __currentObject?: ObjType | null;
12
12
  __options?: object;
13
- notifyChanged(type: string, key: PropOf<ObjType>, value?: any, subvalue?: string): Promise<false | any[] | undefined>;
13
+ notifyChanged(type: string, key: PropOf<ObjType> | string, value?: any, subvalue?: string): Promise<false | any[] | undefined>;
14
14
  get obj(): ObjType | undefined;
15
15
  /**
16
16
  * Get the object this manager is managing
@@ -86,22 +86,7 @@ export declare class SimpleObject extends MapableObject {
86
86
  * @returns
87
87
  */
88
88
  pushValue<MKey extends PropOf<this>>(key: MKey, value: any, sendChanges?: sendChangesType): Promise<this[MKey] | false>;
89
- /**
90
- * notify the manager class when a meta value is changed on this object
91
- * @param type
92
- * @param key
93
- * @param value
94
- * @param subvalue
95
- */
96
- notifyChanged<MKey extends PropOf<this>>(type: "meta", key: string, value: any, subvalue?: any): any;
97
- /**
98
- * notify the manager class when a value is changed on this object
99
- * @param type
100
- * @param key
101
- * @param value
102
- * @param subvalue
103
- */
104
- notifyChanged<MKey extends PropOf<this>>(type: string, key: MKey, value: any, subvalue?: any): any;
89
+ notifyChanged<MKey extends PropOf<this>>(type: string, key: MKey | string, value: any, subvalue?: any): Promise<void>;
105
90
  /**
106
91
  * check if a key can be changed on an object
107
92
  * @param object
@@ -155,6 +140,10 @@ export declare class SimpleObject extends MapableObject {
155
140
  static getIndexOrID(o: any): number;
156
141
  static getIndex(o: any): number;
157
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>;
158
147
  getOriginal(): this | undefined;
159
148
  setOriginal(toObj?: null | 0 | any): this | undefined;
160
149
  static setOriginal<T>(obj: T, toObj?: null | 0 | any): T | undefined;
@@ -646,11 +646,107 @@ 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
+ /* -------------------------------------------------------------------------- */
655
+ /* Events */
656
+ /* -------------------------------------------------------------------------- */
657
+ function () {
658
+ var _event_run = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(eventName) {
659
+ var _this$manager;
660
+ var _len,
661
+ params,
662
+ _key,
663
+ _args7 = arguments;
664
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
665
+ while (1) switch (_context7.prev = _context7.next) {
666
+ case 0:
667
+ if (this.manager) {
668
+ _context7.next = 3;
669
+ break;
670
+ }
671
+ console.error("you cant use events if your object has no manager");
672
+ return _context7.abrupt("return");
673
+ case 3:
674
+ for (_len = _args7.length, params = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
675
+ params[_key - 1] = _args7[_key];
676
+ }
677
+ _context7.next = 6;
678
+ return (_this$manager = this.manager).event_run.apply(_this$manager, [eventName].concat(params));
679
+ case 6:
680
+ return _context7.abrupt("return", _context7.sent);
681
+ case 7:
682
+ case "end":
683
+ return _context7.stop();
684
+ }
685
+ }, _callee7, this);
686
+ }));
687
+ function event_run(_x13) {
688
+ return _event_run.apply(this, arguments);
689
+ }
690
+ return event_run;
691
+ }()
692
+ }, {
693
+ key: "event_use",
694
+ value: function event_use(name, runEvent) {
695
+ var onlyOn = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
696
+ var runOnce = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
697
+ if (!this.manager) {
698
+ console.error("you cant use events if your object has no manager");
699
+ return;
700
+ }
701
+ return this.manager.event_use(name, runEvent, onlyOn, runOnce);
702
+ }
703
+ }, {
704
+ key: "event_remove",
705
+ value: function event_remove(name, uname) {
706
+ if (!this.manager) {
707
+ console.error("you cant use events if your object has no manager");
708
+ return;
709
+ }
710
+ return this.manager.event_remove(name, uname);
711
+ }
712
+ }, {
713
+ key: "event_add",
714
+ value: function () {
715
+ var _event_add = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(name, uname, runEvent) {
716
+ var onlyOn,
717
+ runOnce,
718
+ _args8 = arguments;
719
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
720
+ while (1) switch (_context8.prev = _context8.next) {
721
+ case 0:
722
+ onlyOn = _args8.length > 3 && _args8[3] !== undefined ? _args8[3] : null;
723
+ runOnce = _args8.length > 4 && _args8[4] !== undefined ? _args8[4] : false;
724
+ if (this.manager) {
725
+ _context8.next = 5;
726
+ break;
727
+ }
728
+ console.error("you cant use events if your object has no manager");
729
+ return _context8.abrupt("return");
730
+ case 5:
731
+ _context8.next = 7;
732
+ return this.manager.event_add(name, uname, runEvent, onlyOn, runOnce);
733
+ case 7:
734
+ case "end":
735
+ return _context8.stop();
736
+ }
737
+ }, _callee8, this);
738
+ }));
739
+ function event_add(_x14, _x15, _x16) {
740
+ return _event_add.apply(this, arguments);
741
+ }
742
+ return event_add;
743
+ }()
744
+ /* -------------------------------------------------------------------------- */
651
745
  /* Original */
652
746
  /* -------------------------------------------------------------------------- */
653
- function getOriginal() {
747
+ }, {
748
+ key: "getOriginal",
749
+ value: function getOriginal() {
654
750
  return this.__originalobject || undefined;
655
751
  }
656
752
  }, {
@@ -722,10 +818,10 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
722
818
  delete obj[key];
723
819
  }
724
820
  } 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];
821
+ for (var _key2 in initObject) {
822
+ if (_key2.startsWith("__")) continue;
823
+ if (fullUpdate || Object.prototype.hasOwnProperty.call(obj, _key2)) {
824
+ obj[_key2] = initObject[_key2];
729
825
  }
730
826
  }
731
827
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azrico/webobject",
3
- "version": "1.3.24",
3
+ "version": "1.4.0",
4
4
  "description": "Stateful object",
5
5
  "author": "Azrideus",
6
6
  "license": "MIT",