@hpcc-js/util 2.42.0 → 2.46.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.
Files changed (75) hide show
  1. package/LICENSE +43 -43
  2. package/dist/index.js +2281 -2281
  3. package/dist/index.js.map +1 -1
  4. package/dist/index.min.js +1 -1
  5. package/dist/index.min.js.map +1 -1
  6. package/lib-es6/__package__.js +3 -3
  7. package/lib-es6/__package__.js.map +1 -1
  8. package/lib-es6/array.js +84 -84
  9. package/lib-es6/cache.js +60 -60
  10. package/lib-es6/debounce.js +85 -85
  11. package/lib-es6/dictionary.js +61 -61
  12. package/lib-es6/dispatch.js +101 -101
  13. package/lib-es6/esp.js +32 -32
  14. package/lib-es6/graph.js +348 -348
  15. package/lib-es6/graph2.js +603 -603
  16. package/lib-es6/hashSum.js +49 -49
  17. package/lib-es6/immutable.js +54 -54
  18. package/lib-es6/index.js +21 -21
  19. package/lib-es6/logging.js +177 -177
  20. package/lib-es6/math.js +90 -90
  21. package/lib-es6/object.js +121 -121
  22. package/lib-es6/observer.js +79 -79
  23. package/lib-es6/platform.js +17 -17
  24. package/lib-es6/saxParser.js +125 -125
  25. package/lib-es6/stack.js +41 -41
  26. package/lib-es6/stateful.js +170 -170
  27. package/lib-es6/string.js +22 -22
  28. package/lib-es6/url.js +32 -32
  29. package/package.json +7 -21
  30. package/src/__package__.ts +2 -2
  31. package/src/array.ts +98 -98
  32. package/src/cache.ts +65 -65
  33. package/src/debounce.ts +88 -88
  34. package/src/dictionary.ts +69 -69
  35. package/src/dispatch.ts +119 -119
  36. package/src/esp.ts +32 -32
  37. package/src/graph.ts +353 -353
  38. package/src/graph2.ts +661 -661
  39. package/src/hashSum.ts +55 -55
  40. package/src/immutable.ts +57 -57
  41. package/src/index.ts +21 -21
  42. package/src/logging.ts +211 -211
  43. package/src/math.ts +92 -92
  44. package/src/object.ts +117 -117
  45. package/src/observer.ts +91 -91
  46. package/src/platform.ts +20 -20
  47. package/src/saxParser.ts +135 -135
  48. package/src/stack.ts +41 -41
  49. package/src/stateful.ts +178 -178
  50. package/src/string.ts +21 -21
  51. package/src/url.ts +27 -27
  52. package/types/__package__.d.ts +3 -3
  53. package/types/__package__.d.ts.map +1 -1
  54. package/types/array.d.ts +13 -13
  55. package/types/cache.d.ts +20 -20
  56. package/types/debounce.d.ts +12 -12
  57. package/types/dictionary.d.ts +20 -20
  58. package/types/dispatch.d.ts +26 -26
  59. package/types/esp.d.ts +1 -1
  60. package/types/graph.d.ts +73 -73
  61. package/types/graph2.d.ts +111 -111
  62. package/types/hashSum.d.ts +1 -1
  63. package/types/immutable.d.ts +2 -2
  64. package/types/index.d.ts +21 -21
  65. package/types/logging.d.ts +57 -57
  66. package/types/math.d.ts +70 -70
  67. package/types/object.d.ts +48 -48
  68. package/types/observer.d.ts +18 -18
  69. package/types/platform.d.ts +5 -5
  70. package/types/saxParser.d.ts +28 -28
  71. package/types/stack.d.ts +28 -28
  72. package/types/stateful.d.ts +33 -33
  73. package/types/string.d.ts +2 -2
  74. package/types/url.d.ts +2 -2
  75. package/types-3.4/__package__.d.ts +2 -2
@@ -1,126 +1,126 @@
1
- import { __extends } from "tslib";
2
- import { Stack } from "./stack";
3
- var XMLNode = /** @class */ (function () {
4
- function XMLNode(name) {
5
- this.name = "";
6
- this.$ = {};
7
- this._children = [];
8
- this.content = "";
9
- this.name = name;
10
- }
11
- XMLNode.prototype.appendAttribute = function (key, val) {
12
- this.$[key] = val;
13
- };
14
- XMLNode.prototype.appendContent = function (content) {
15
- this.content += content;
16
- };
17
- XMLNode.prototype.appendChild = function (child) {
18
- this._children.push(child);
19
- };
20
- XMLNode.prototype.children = function (tag) {
21
- if (tag === undefined) {
22
- return this._children;
23
- }
24
- return this._children.filter(function (xmlNode) {
25
- return xmlNode.name === tag;
26
- });
27
- };
28
- return XMLNode;
29
- }());
30
- export { XMLNode };
31
- var SAXStackParser = /** @class */ (function () {
32
- function SAXStackParser() {
33
- this.stack = new Stack();
34
- }
35
- SAXStackParser.prototype.walkDoc = function (node) {
36
- var xmlNode = this._startXMLNode(node);
37
- if (node.attributes) {
38
- for (var i = 0; i < node.attributes.length; ++i) {
39
- var attribute = node.attributes.item(i);
40
- this.attributes(attribute.nodeName, attribute.nodeValue);
41
- }
42
- }
43
- this.startXMLNode(xmlNode);
44
- if (node.childNodes) {
45
- for (var i = 0; i < node.childNodes.length; ++i) {
46
- var childNode = node.childNodes.item(i);
47
- if (childNode.nodeType === childNode.TEXT_NODE) {
48
- this.characters(childNode.nodeValue);
49
- }
50
- else {
51
- this.walkDoc(childNode);
52
- }
53
- }
54
- }
55
- this.endXMLNode(this.stack.pop());
56
- };
57
- SAXStackParser.prototype._startXMLNode = function (node) {
58
- var newNode = new XMLNode(node.nodeName);
59
- if (!this.stack.depth()) {
60
- this.root = newNode;
61
- }
62
- else {
63
- this.stack.top().appendChild(newNode);
64
- }
65
- return this.stack.push(newNode);
66
- };
67
- SAXStackParser.prototype.parse = function (xml) {
68
- var domParser = new DOMParser();
69
- var doc = domParser.parseFromString(xml, "application/xml");
70
- this.startDocument();
71
- this.walkDoc(doc);
72
- this.endDocument();
73
- };
74
- // Callbacks ---
75
- SAXStackParser.prototype.startDocument = function () {
76
- };
77
- SAXStackParser.prototype.endDocument = function () {
78
- };
79
- SAXStackParser.prototype.startXMLNode = function (node) {
80
- };
81
- SAXStackParser.prototype.endXMLNode = function (node) {
82
- };
83
- SAXStackParser.prototype.attributes = function (key, val) {
84
- this.stack.top().appendAttribute(key, val);
85
- };
86
- SAXStackParser.prototype.characters = function (text) {
87
- this.stack.top().appendContent(text);
88
- };
89
- return SAXStackParser;
90
- }());
91
- export { SAXStackParser };
92
- var XML2JSONParser = /** @class */ (function (_super) {
93
- __extends(XML2JSONParser, _super);
94
- function XML2JSONParser() {
95
- return _super !== null && _super.apply(this, arguments) || this;
96
- }
97
- XML2JSONParser.prototype.startXMLNode = function (node) {
98
- _super.prototype.startXMLNode.call(this, node);
99
- switch (node.name) {
100
- case "xs:element":
101
- break;
102
- case "xs:simpleType":
103
- break;
104
- default:
105
- break;
106
- }
107
- };
108
- XML2JSONParser.prototype.endXMLNode = function (node) {
109
- switch (node.name) {
110
- case "xs:element":
111
- break;
112
- case "xs:simpleType":
113
- break;
114
- default:
115
- break;
116
- }
117
- _super.prototype.endXMLNode.call(this, node);
118
- };
119
- return XML2JSONParser;
120
- }(SAXStackParser));
121
- export function xml2json(xml) {
122
- var saxParser = new XML2JSONParser();
123
- saxParser.parse(xml);
124
- return saxParser.root;
125
- }
1
+ import { __extends } from "tslib";
2
+ import { Stack } from "./stack";
3
+ var XMLNode = /** @class */ (function () {
4
+ function XMLNode(name) {
5
+ this.name = "";
6
+ this.$ = {};
7
+ this._children = [];
8
+ this.content = "";
9
+ this.name = name;
10
+ }
11
+ XMLNode.prototype.appendAttribute = function (key, val) {
12
+ this.$[key] = val;
13
+ };
14
+ XMLNode.prototype.appendContent = function (content) {
15
+ this.content += content;
16
+ };
17
+ XMLNode.prototype.appendChild = function (child) {
18
+ this._children.push(child);
19
+ };
20
+ XMLNode.prototype.children = function (tag) {
21
+ if (tag === undefined) {
22
+ return this._children;
23
+ }
24
+ return this._children.filter(function (xmlNode) {
25
+ return xmlNode.name === tag;
26
+ });
27
+ };
28
+ return XMLNode;
29
+ }());
30
+ export { XMLNode };
31
+ var SAXStackParser = /** @class */ (function () {
32
+ function SAXStackParser() {
33
+ this.stack = new Stack();
34
+ }
35
+ SAXStackParser.prototype.walkDoc = function (node) {
36
+ var xmlNode = this._startXMLNode(node);
37
+ if (node.attributes) {
38
+ for (var i = 0; i < node.attributes.length; ++i) {
39
+ var attribute = node.attributes.item(i);
40
+ this.attributes(attribute.nodeName, attribute.nodeValue);
41
+ }
42
+ }
43
+ this.startXMLNode(xmlNode);
44
+ if (node.childNodes) {
45
+ for (var i = 0; i < node.childNodes.length; ++i) {
46
+ var childNode = node.childNodes.item(i);
47
+ if (childNode.nodeType === childNode.TEXT_NODE) {
48
+ this.characters(childNode.nodeValue);
49
+ }
50
+ else {
51
+ this.walkDoc(childNode);
52
+ }
53
+ }
54
+ }
55
+ this.endXMLNode(this.stack.pop());
56
+ };
57
+ SAXStackParser.prototype._startXMLNode = function (node) {
58
+ var newNode = new XMLNode(node.nodeName);
59
+ if (!this.stack.depth()) {
60
+ this.root = newNode;
61
+ }
62
+ else {
63
+ this.stack.top().appendChild(newNode);
64
+ }
65
+ return this.stack.push(newNode);
66
+ };
67
+ SAXStackParser.prototype.parse = function (xml) {
68
+ var domParser = new DOMParser();
69
+ var doc = domParser.parseFromString(xml, "application/xml");
70
+ this.startDocument();
71
+ this.walkDoc(doc);
72
+ this.endDocument();
73
+ };
74
+ // Callbacks ---
75
+ SAXStackParser.prototype.startDocument = function () {
76
+ };
77
+ SAXStackParser.prototype.endDocument = function () {
78
+ };
79
+ SAXStackParser.prototype.startXMLNode = function (node) {
80
+ };
81
+ SAXStackParser.prototype.endXMLNode = function (node) {
82
+ };
83
+ SAXStackParser.prototype.attributes = function (key, val) {
84
+ this.stack.top().appendAttribute(key, val);
85
+ };
86
+ SAXStackParser.prototype.characters = function (text) {
87
+ this.stack.top().appendContent(text);
88
+ };
89
+ return SAXStackParser;
90
+ }());
91
+ export { SAXStackParser };
92
+ var XML2JSONParser = /** @class */ (function (_super) {
93
+ __extends(XML2JSONParser, _super);
94
+ function XML2JSONParser() {
95
+ return _super !== null && _super.apply(this, arguments) || this;
96
+ }
97
+ XML2JSONParser.prototype.startXMLNode = function (node) {
98
+ _super.prototype.startXMLNode.call(this, node);
99
+ switch (node.name) {
100
+ case "xs:element":
101
+ break;
102
+ case "xs:simpleType":
103
+ break;
104
+ default:
105
+ break;
106
+ }
107
+ };
108
+ XML2JSONParser.prototype.endXMLNode = function (node) {
109
+ switch (node.name) {
110
+ case "xs:element":
111
+ break;
112
+ case "xs:simpleType":
113
+ break;
114
+ default:
115
+ break;
116
+ }
117
+ _super.prototype.endXMLNode.call(this, node);
118
+ };
119
+ return XML2JSONParser;
120
+ }(SAXStackParser));
121
+ export function xml2json(xml) {
122
+ var saxParser = new XML2JSONParser();
123
+ saxParser.parse(xml);
124
+ return saxParser.root;
125
+ }
126
126
  //# sourceMappingURL=saxParser.js.map
package/lib-es6/stack.js CHANGED
@@ -1,42 +1,42 @@
1
- /**
2
- * A generic Stack
3
- */
4
- var Stack = /** @class */ (function () {
5
- function Stack() {
6
- this.stack = [];
7
- }
8
- /**
9
- * Push element onto the stack
10
- *
11
- * @param e - element to push
12
- */
13
- Stack.prototype.push = function (e) {
14
- this.stack.push(e);
15
- return e;
16
- };
17
- /**
18
- * Pop element off the stack
19
- */
20
- Stack.prototype.pop = function () {
21
- return this.stack.pop();
22
- };
23
- /**
24
- * Top item on the stack
25
- *
26
- * @returns Top element on the stack
27
- */
28
- Stack.prototype.top = function () {
29
- return this.stack.length ? this.stack[this.stack.length - 1] : undefined;
30
- };
31
- /**
32
- * Depth of stack
33
- *
34
- * @returns Depth
35
- */
36
- Stack.prototype.depth = function () {
37
- return this.stack.length;
38
- };
39
- return Stack;
40
- }());
41
- export { Stack };
1
+ /**
2
+ * A generic Stack
3
+ */
4
+ var Stack = /** @class */ (function () {
5
+ function Stack() {
6
+ this.stack = [];
7
+ }
8
+ /**
9
+ * Push element onto the stack
10
+ *
11
+ * @param e - element to push
12
+ */
13
+ Stack.prototype.push = function (e) {
14
+ this.stack.push(e);
15
+ return e;
16
+ };
17
+ /**
18
+ * Pop element off the stack
19
+ */
20
+ Stack.prototype.pop = function () {
21
+ return this.stack.pop();
22
+ };
23
+ /**
24
+ * Top item on the stack
25
+ *
26
+ * @returns Top element on the stack
27
+ */
28
+ Stack.prototype.top = function () {
29
+ return this.stack.length ? this.stack[this.stack.length - 1] : undefined;
30
+ };
31
+ /**
32
+ * Depth of stack
33
+ *
34
+ * @returns Depth
35
+ */
36
+ Stack.prototype.depth = function () {
37
+ return this.stack.length;
38
+ };
39
+ return Stack;
40
+ }());
41
+ export { Stack };
42
42
  //# sourceMappingURL=stack.js.map
@@ -1,171 +1,171 @@
1
- import { __awaiter, __extends, __generator } from "tslib";
2
- import { Dispatch, Message } from "./dispatch";
3
- import { deepEquals } from "./immutable";
4
- var PropChangedMessage = /** @class */ (function (_super) {
5
- __extends(PropChangedMessage, _super);
6
- function PropChangedMessage(property, newValue, oldValue) {
7
- var _this = _super.call(this) || this;
8
- _this.property = property;
9
- _this.newValue = newValue;
10
- _this.oldValue = oldValue;
11
- return _this;
12
- }
13
- Object.defineProperty(PropChangedMessage.prototype, "canConflate", {
14
- get: function () { return true; },
15
- enumerable: false,
16
- configurable: true
17
- });
18
- PropChangedMessage.prototype.conflate = function (other) {
19
- if (this.property === other.property) {
20
- this.newValue = other.newValue;
21
- return true;
22
- }
23
- return false;
24
- };
25
- PropChangedMessage.prototype.void = function () {
26
- return deepEquals(this.newValue, this.oldValue);
27
- };
28
- return PropChangedMessage;
29
- }(Message));
30
- var StateObject = /** @class */ (function () {
31
- function StateObject() {
32
- this._espState = {};
33
- this._dispatch = new Dispatch();
34
- this._monitorTickCount = 0;
35
- }
36
- StateObject.prototype.clear = function (newVals) {
37
- this._espState = {};
38
- if (newVals !== void 0) {
39
- this.set(newVals);
40
- }
41
- this._monitorTickCount = 0;
42
- };
43
- StateObject.prototype.get = function (key, defValue) {
44
- if (key === void 0) {
45
- return this._espState;
46
- }
47
- return this.has(key) ? this._espState[key] : defValue;
48
- };
49
- StateObject.prototype.set = function (keyOrNewVals, newVal) {
50
- if (typeof keyOrNewVals === "string") {
51
- return this.setSingle(keyOrNewVals, newVal); // TODO: "as any" should not be needed (TS >= 3.1.x)
52
- }
53
- this.setAll(keyOrNewVals);
54
- };
55
- StateObject.prototype.setSingle = function (key, newVal) {
56
- var oldVal = this._espState[key];
57
- this._espState[key] = newVal;
58
- this._dispatch.post(new PropChangedMessage(key, newVal, oldVal));
59
- };
60
- StateObject.prototype.setAll = function (_) {
61
- for (var key in _) {
62
- if (_.hasOwnProperty(key)) {
63
- this.setSingle(key, _[key]);
64
- }
65
- }
66
- };
67
- StateObject.prototype.has = function (key) {
68
- return this._espState[key] !== void 0;
69
- };
70
- StateObject.prototype.addObserver = function (eventID, propIDOrCallback, callback) {
71
- if (this.isCallback(propIDOrCallback)) {
72
- if (eventID !== "changed")
73
- throw new Error("Invalid eventID: " + eventID);
74
- return this._dispatch.attach(function (messages) {
75
- propIDOrCallback(messages.map(function (m) { return ({
76
- id: m.property,
77
- oldValue: m.oldValue,
78
- newValue: m.newValue
79
- }); }));
80
- });
81
- }
82
- else {
83
- if (eventID !== "propChanged")
84
- throw new Error("Invalid eventID: " + eventID);
85
- return this._dispatch.attach(function (messages) {
86
- var filteredMessages = messages.filter(function (m) { return m.property === propIDOrCallback; });
87
- if (filteredMessages.length) {
88
- if (filteredMessages.length > 1) {
89
- console.warn("Should only be 1 message?");
90
- }
91
- var event_1 = filteredMessages[filteredMessages.length - 1];
92
- callback({
93
- id: event_1.property,
94
- oldValue: event_1.oldValue,
95
- newValue: event_1.newValue
96
- });
97
- }
98
- });
99
- }
100
- };
101
- StateObject.prototype.on = function (eventID, propIDOrCallback, callback) {
102
- this.addObserver(eventID, propIDOrCallback, callback);
103
- return this;
104
- };
105
- StateObject.prototype.isCallback = function (propIDOrCallback) {
106
- return (typeof propIDOrCallback === "function");
107
- };
108
- StateObject.prototype.hasEventListener = function () {
109
- return this._dispatch.hasObserver();
110
- };
111
- // Monitoring ---
112
- StateObject.prototype.refresh = function (full) {
113
- if (full === void 0) { full = false; }
114
- return __awaiter(this, void 0, void 0, function () {
115
- return __generator(this, function (_a) {
116
- switch (_a.label) {
117
- case 0: return [4 /*yield*/, Promise.resolve()];
118
- case 1:
119
- _a.sent();
120
- return [2 /*return*/, this];
121
- }
122
- });
123
- });
124
- };
125
- StateObject.prototype._monitor = function () {
126
- var _this = this;
127
- if (this._monitorHandle) {
128
- this._monitorTickCount = 0;
129
- return;
130
- }
131
- this._monitorHandle = setTimeout(function () {
132
- var refreshPromise = _this.hasEventListener() ? _this.refresh() : Promise.resolve();
133
- refreshPromise.then(function () {
134
- _this._monitor();
135
- });
136
- delete _this._monitorHandle;
137
- }, this._monitorTimeoutDuraction());
138
- };
139
- StateObject.prototype._monitorTimeoutDuraction = function () {
140
- ++this._monitorTickCount;
141
- if (this._monitorTickCount <= 1) { // Once
142
- return 0;
143
- }
144
- return 30000;
145
- };
146
- StateObject.prototype.watch = function (callback, triggerChange) {
147
- var _this = this;
148
- if (triggerChange === void 0) { triggerChange = true; }
149
- if (typeof callback !== "function") {
150
- throw new Error("Invalid Callback");
151
- }
152
- if (triggerChange) {
153
- setTimeout(function () {
154
- var props = _this.get();
155
- var changes = [];
156
- for (var key in props) {
157
- if (props.hasOwnProperty(props)) {
158
- changes.push({ id: key, newValue: props[key], oldValue: undefined });
159
- }
160
- }
161
- callback(changes);
162
- }, 0);
163
- }
164
- var retVal = this.addObserver("changed", callback);
165
- this._monitor();
166
- return retVal;
167
- };
168
- return StateObject;
169
- }());
170
- export { StateObject };
1
+ import { __awaiter, __extends, __generator } from "tslib";
2
+ import { Dispatch, Message } from "./dispatch";
3
+ import { deepEquals } from "./immutable";
4
+ var PropChangedMessage = /** @class */ (function (_super) {
5
+ __extends(PropChangedMessage, _super);
6
+ function PropChangedMessage(property, newValue, oldValue) {
7
+ var _this = _super.call(this) || this;
8
+ _this.property = property;
9
+ _this.newValue = newValue;
10
+ _this.oldValue = oldValue;
11
+ return _this;
12
+ }
13
+ Object.defineProperty(PropChangedMessage.prototype, "canConflate", {
14
+ get: function () { return true; },
15
+ enumerable: false,
16
+ configurable: true
17
+ });
18
+ PropChangedMessage.prototype.conflate = function (other) {
19
+ if (this.property === other.property) {
20
+ this.newValue = other.newValue;
21
+ return true;
22
+ }
23
+ return false;
24
+ };
25
+ PropChangedMessage.prototype.void = function () {
26
+ return deepEquals(this.newValue, this.oldValue);
27
+ };
28
+ return PropChangedMessage;
29
+ }(Message));
30
+ var StateObject = /** @class */ (function () {
31
+ function StateObject() {
32
+ this._espState = {};
33
+ this._dispatch = new Dispatch();
34
+ this._monitorTickCount = 0;
35
+ }
36
+ StateObject.prototype.clear = function (newVals) {
37
+ this._espState = {};
38
+ if (newVals !== void 0) {
39
+ this.set(newVals);
40
+ }
41
+ this._monitorTickCount = 0;
42
+ };
43
+ StateObject.prototype.get = function (key, defValue) {
44
+ if (key === void 0) {
45
+ return this._espState;
46
+ }
47
+ return this.has(key) ? this._espState[key] : defValue;
48
+ };
49
+ StateObject.prototype.set = function (keyOrNewVals, newVal) {
50
+ if (typeof keyOrNewVals === "string") {
51
+ return this.setSingle(keyOrNewVals, newVal); // TODO: "as any" should not be needed (TS >= 3.1.x)
52
+ }
53
+ this.setAll(keyOrNewVals);
54
+ };
55
+ StateObject.prototype.setSingle = function (key, newVal) {
56
+ var oldVal = this._espState[key];
57
+ this._espState[key] = newVal;
58
+ this._dispatch.post(new PropChangedMessage(key, newVal, oldVal));
59
+ };
60
+ StateObject.prototype.setAll = function (_) {
61
+ for (var key in _) {
62
+ if (_.hasOwnProperty(key)) {
63
+ this.setSingle(key, _[key]);
64
+ }
65
+ }
66
+ };
67
+ StateObject.prototype.has = function (key) {
68
+ return this._espState[key] !== void 0;
69
+ };
70
+ StateObject.prototype.addObserver = function (eventID, propIDOrCallback, callback) {
71
+ if (this.isCallback(propIDOrCallback)) {
72
+ if (eventID !== "changed")
73
+ throw new Error("Invalid eventID: " + eventID);
74
+ return this._dispatch.attach(function (messages) {
75
+ propIDOrCallback(messages.map(function (m) { return ({
76
+ id: m.property,
77
+ oldValue: m.oldValue,
78
+ newValue: m.newValue
79
+ }); }));
80
+ });
81
+ }
82
+ else {
83
+ if (eventID !== "propChanged")
84
+ throw new Error("Invalid eventID: " + eventID);
85
+ return this._dispatch.attach(function (messages) {
86
+ var filteredMessages = messages.filter(function (m) { return m.property === propIDOrCallback; });
87
+ if (filteredMessages.length) {
88
+ if (filteredMessages.length > 1) {
89
+ console.warn("Should only be 1 message?");
90
+ }
91
+ var event_1 = filteredMessages[filteredMessages.length - 1];
92
+ callback({
93
+ id: event_1.property,
94
+ oldValue: event_1.oldValue,
95
+ newValue: event_1.newValue
96
+ });
97
+ }
98
+ });
99
+ }
100
+ };
101
+ StateObject.prototype.on = function (eventID, propIDOrCallback, callback) {
102
+ this.addObserver(eventID, propIDOrCallback, callback);
103
+ return this;
104
+ };
105
+ StateObject.prototype.isCallback = function (propIDOrCallback) {
106
+ return (typeof propIDOrCallback === "function");
107
+ };
108
+ StateObject.prototype.hasEventListener = function () {
109
+ return this._dispatch.hasObserver();
110
+ };
111
+ // Monitoring ---
112
+ StateObject.prototype.refresh = function (full) {
113
+ if (full === void 0) { full = false; }
114
+ return __awaiter(this, void 0, void 0, function () {
115
+ return __generator(this, function (_a) {
116
+ switch (_a.label) {
117
+ case 0: return [4 /*yield*/, Promise.resolve()];
118
+ case 1:
119
+ _a.sent();
120
+ return [2 /*return*/, this];
121
+ }
122
+ });
123
+ });
124
+ };
125
+ StateObject.prototype._monitor = function () {
126
+ var _this = this;
127
+ if (this._monitorHandle) {
128
+ this._monitorTickCount = 0;
129
+ return;
130
+ }
131
+ this._monitorHandle = setTimeout(function () {
132
+ var refreshPromise = _this.hasEventListener() ? _this.refresh() : Promise.resolve();
133
+ refreshPromise.then(function () {
134
+ _this._monitor();
135
+ });
136
+ delete _this._monitorHandle;
137
+ }, this._monitorTimeoutDuraction());
138
+ };
139
+ StateObject.prototype._monitorTimeoutDuraction = function () {
140
+ ++this._monitorTickCount;
141
+ if (this._monitorTickCount <= 1) { // Once
142
+ return 0;
143
+ }
144
+ return 30000;
145
+ };
146
+ StateObject.prototype.watch = function (callback, triggerChange) {
147
+ var _this = this;
148
+ if (triggerChange === void 0) { triggerChange = true; }
149
+ if (typeof callback !== "function") {
150
+ throw new Error("Invalid Callback");
151
+ }
152
+ if (triggerChange) {
153
+ setTimeout(function () {
154
+ var props = _this.get();
155
+ var changes = [];
156
+ for (var key in props) {
157
+ if (props.hasOwnProperty(props)) {
158
+ changes.push({ id: key, newValue: props[key], oldValue: undefined });
159
+ }
160
+ }
161
+ callback(changes);
162
+ }, 0);
163
+ }
164
+ var retVal = this.addObserver("changed", callback);
165
+ this._monitor();
166
+ return retVal;
167
+ };
168
+ return StateObject;
169
+ }());
170
+ export { StateObject };
171
171
  //# sourceMappingURL=stateful.js.map