ismx-nexo-node-app 0.4.73 → 0.4.74

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.
@@ -8,7 +8,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
11
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
+ const DateUtils_1 = __importDefault(require("./utils/DateUtils"));
12
16
  class BusinessState {
13
17
  constructor() {
14
18
  this.listeners = {};
@@ -34,12 +38,20 @@ class BusinessState {
34
38
  }
35
39
  notify(data) {
36
40
  var _a, _b;
37
- this.data = data !== null && data !== void 0 ? data : this.data;
41
+ this.data = this.clone(data !== null && data !== void 0 ? data : this.data);
38
42
  for (let l in this.listeners)
39
43
  try {
40
44
  (_b = (_a = this.listeners)[l]) === null || _b === void 0 ? void 0 : _b.call(_a, this.data);
41
45
  }
42
46
  catch (error) { }
43
47
  }
48
+ clone(data) {
49
+ if (!data)
50
+ return data;
51
+ return JSON.parse(JSON.stringify(data), this.reviver);
52
+ }
53
+ reviver(key, value) {
54
+ return DateUtils_1.default.isIsoDate(value) ? new Date(value) : value;
55
+ }
44
56
  }
45
57
  exports.default = BusinessState;
@@ -9,4 +9,6 @@ export default class BusinessState<Model> {
9
9
  observeId(id: string, listener: (data: Model) => any, runOnObserve?: boolean): string;
10
10
  protected remove(id: string): void;
11
11
  protected notify(data?: Model): void;
12
+ protected clone(data: Model): Model;
13
+ private reviver;
12
14
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ismx-nexo-node-app",
3
- "version": "0.4.73",
3
+ "version": "0.4.74",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "build": "rm -rf ./dist && npx tsc",
@@ -1,3 +1,5 @@
1
+ import DateUtils from "./utils/DateUtils";
2
+
1
3
  export default class BusinessState<Model>
2
4
  {
3
5
  data!: Model;
@@ -23,8 +25,17 @@ export default class BusinessState<Model>
23
25
  }
24
26
 
25
27
  protected notify(data?: Model): void {
26
- this.data = data ?? this.data;
28
+ this.data = this.clone(data ?? this.data);
27
29
  for (let l in this.listeners)
28
30
  try { this.listeners[l]?.(this.data); } catch (error) {}
29
31
  }
32
+
33
+ protected clone(data: Model): Model {
34
+ if (!data) return data;
35
+ return JSON.parse(JSON.stringify(data), this.reviver) as Model;
36
+ }
37
+
38
+ private reviver(key: string, value: string) {
39
+ return DateUtils.isIsoDate(value) ? new Date(value) : value;
40
+ }
30
41
  }