react-app-store-manager 1.1.2 → 1.2.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/dist/index.d.ts CHANGED
@@ -13,6 +13,7 @@ export declare class Store implements StoreInterface<any> {
13
13
  changeCallbacks: any[];
14
14
  get: () => any;
15
15
  update(callback: any): void;
16
+ isEqual(newValue: any, oldValue: any): boolean;
16
17
  addListener: (onChange: any) => number;
17
18
  removeListener: (onChange: any) => any[];
18
19
  }
package/dist/index.js CHANGED
@@ -17,10 +17,43 @@ var Store = /** @class */ (function () {
17
17
  }
18
18
  Store.prototype.update = function (callback) {
19
19
  var _this = this;
20
- this.value = callback(this.value);
21
- this.changeCallbacks.forEach(function (callback) {
22
- callback(_this.value);
23
- });
20
+ var newValue = callback(this.value);
21
+ if (!this.isEqual(newValue, this.value)) {
22
+ this.value = newValue;
23
+ this.changeCallbacks.forEach(function (callback) {
24
+ callback(_this.value);
25
+ });
26
+ }
27
+ };
28
+ Store.prototype.isEqual = function (newValue, oldValue) {
29
+ switch (typeof newValue) {
30
+ case "number":
31
+ case "string":
32
+ case "boolean":
33
+ case "undefined":
34
+ case "bigint":
35
+ case "symbol": {
36
+ return oldValue === newValue;
37
+ }
38
+ case "function": {
39
+ return (newValue === null || newValue === void 0 ? void 0 : newValue.toString()) === (oldValue === null || oldValue === void 0 ? void 0 : oldValue.toString());
40
+ }
41
+ case "object": {
42
+ if (!Object.keys(newValue) && Object.keys(newValue)) {
43
+ return false;
44
+ }
45
+ for (var prop in newValue) {
46
+ if (!this.isEqual(newValue === null || newValue === void 0 ? void 0 : newValue[prop], oldValue === null || oldValue === void 0 ? void 0 : oldValue[prop])) {
47
+ return false;
48
+ }
49
+ }
50
+ break;
51
+ }
52
+ default: {
53
+ return false;
54
+ }
55
+ }
56
+ return true;
24
57
  };
25
58
  return Store;
26
59
  }());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-app-store-manager",
3
- "version": "1.1.2",
3
+ "version": "1.2.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",