react-app-store-manager 1.4.8 → 1.4.12
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/{src → dist}/Provider.d.ts +0 -0
- package/{src → dist}/Provider.js +13 -12
- package/{src → dist}/Store.d.ts +0 -0
- package/dist/Store.js +34 -0
- package/{src → dist}/createStore.d.ts +0 -0
- package/{src → dist}/createStore.js +2 -2
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1 -0
- package/{src → dist}/isEqual.d.ts +0 -0
- package/{src → dist}/isEqual.js +3 -3
- package/{src → dist}/useStore.d.ts +0 -0
- package/{src → dist}/useStore.js +2 -2
- package/package.json +7 -8
- package/index.d.ts +0 -6
- package/index.js +0 -2
- package/src/Store.js +0 -33
File without changes
|
package/{src → dist}/Provider.js
RENAMED
@@ -22,21 +22,22 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
22
|
__setModuleDefault(result, mod);
|
23
23
|
return result;
|
24
24
|
};
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
(0, react_1.
|
32
|
-
|
33
|
-
|
25
|
+
exports.__esModule = true;
|
26
|
+
var react_1 = __importStar(require("react"));
|
27
|
+
var Provider = function (_a) {
|
28
|
+
var store = _a.store, children = _a.children;
|
29
|
+
var Provider = store.context;
|
30
|
+
var _b = (0, react_1.useReducer)(function (x) { return !x; }, true), updater = _b[0], forceUpdate = _b[1];
|
31
|
+
var value = (0, react_1.useMemo)(function () { return store.value; }, [store.value, updater]);
|
32
|
+
(0, react_1.useEffect)(function () {
|
33
|
+
var listener = {
|
34
|
+
onUpdate: function () {
|
34
35
|
forceUpdate();
|
35
36
|
}
|
36
37
|
};
|
37
38
|
store.subscribe(listener);
|
38
|
-
return ()
|
39
|
+
return function () { return store.unsubscribe(listener); };
|
39
40
|
}, [store]);
|
40
|
-
return (react_1
|
41
|
+
return (react_1["default"].createElement(Provider.Provider, { value: value }, children));
|
41
42
|
};
|
42
|
-
exports
|
43
|
+
exports["default"] = Provider;
|
package/{src → dist}/Store.d.ts
RENAMED
File without changes
|
package/dist/Store.js
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
exports.__esModule = true;
|
6
|
+
exports.Store = void 0;
|
7
|
+
var react_1 = __importDefault(require("react"));
|
8
|
+
var isEqual_1 = require("./isEqual");
|
9
|
+
var Store = /** @class */ (function () {
|
10
|
+
function Store(value, actions) {
|
11
|
+
this.listeners = [];
|
12
|
+
this.context = react_1["default"].createContext(value);
|
13
|
+
this.value = value;
|
14
|
+
this.actions = actions;
|
15
|
+
}
|
16
|
+
Store.prototype.update = function (callback) {
|
17
|
+
var newValue = callback(this.value);
|
18
|
+
if (!(0, isEqual_1.isEqual)(newValue, this.value)) {
|
19
|
+
this.value = newValue;
|
20
|
+
this.listeners.map(function (listener) { return listener.onUpdate(); });
|
21
|
+
}
|
22
|
+
};
|
23
|
+
Store.prototype.action = function (callback) {
|
24
|
+
callback(this.actions);
|
25
|
+
};
|
26
|
+
Store.prototype.subscribe = function (listener) {
|
27
|
+
this.listeners.push(listener);
|
28
|
+
};
|
29
|
+
Store.prototype.unsubscribe = function (listener) {
|
30
|
+
this.listeners = this.listeners.filter(function (l) { return l !== listener; });
|
31
|
+
};
|
32
|
+
return Store;
|
33
|
+
}());
|
34
|
+
exports.Store = Store;
|
File without changes
|
@@ -1,7 +1,7 @@
|
|
1
1
|
"use strict";
|
2
|
-
|
2
|
+
exports.__esModule = true;
|
3
3
|
exports.createStore = void 0;
|
4
|
-
|
4
|
+
var Store_1 = require("./Store");
|
5
5
|
function createStore(value, actions) {
|
6
6
|
return new Store_1.Store(value, actions !== null && actions !== void 0 ? actions : {});
|
7
7
|
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";
|
File without changes
|
package/{src → dist}/isEqual.js
RENAMED
@@ -1,5 +1,5 @@
|
|
1
1
|
"use strict";
|
2
|
-
|
2
|
+
exports.__esModule = true;
|
3
3
|
exports.isEqual = void 0;
|
4
4
|
function isEqual(newValue, oldValue) {
|
5
5
|
switch (typeof (newValue)) {
|
@@ -9,13 +9,13 @@ function isEqual(newValue, oldValue) {
|
|
9
9
|
}
|
10
10
|
if (newValue instanceof Date && oldValue instanceof Date && String(newValue) !== String(oldValue))
|
11
11
|
return false;
|
12
|
-
for (
|
12
|
+
for (var prop in newValue) {
|
13
13
|
if (newValue.hasOwnProperty(prop) !== (oldValue === null || oldValue === void 0 ? void 0 : oldValue.hasOwnProperty(prop)))
|
14
14
|
return false;
|
15
15
|
if (!isEqual(newValue === null || newValue === void 0 ? void 0 : newValue[prop], oldValue === null || oldValue === void 0 ? void 0 : oldValue[prop]))
|
16
16
|
return false;
|
17
17
|
}
|
18
|
-
for (
|
18
|
+
for (var prop in oldValue) {
|
19
19
|
if (typeof (newValue[prop]) == 'undefined')
|
20
20
|
return false;
|
21
21
|
}
|
File without changes
|
package/{src → dist}/useStore.js
RENAMED
@@ -1,7 +1,7 @@
|
|
1
1
|
"use strict";
|
2
|
-
|
2
|
+
exports.__esModule = true;
|
3
3
|
exports.useStore = void 0;
|
4
|
-
|
4
|
+
var react_1 = require("react");
|
5
5
|
function useStore(store) {
|
6
6
|
return (0, react_1.useContext)(store.context);
|
7
7
|
}
|
package/package.json
CHANGED
@@ -1,21 +1,19 @@
|
|
1
1
|
{
|
2
2
|
"name": "react-app-store-manager",
|
3
|
-
"version": "1.4.
|
3
|
+
"version": "1.4.12",
|
4
4
|
"description": "",
|
5
|
-
"types": "index.d.ts",
|
5
|
+
"types": "dist/index.d.ts",
|
6
6
|
"scripts": {
|
7
|
-
"build": "tsc"
|
8
|
-
"publish": "npm publish"
|
7
|
+
"build": "tsc --declaration"
|
9
8
|
},
|
10
|
-
"main": "index.js",
|
9
|
+
"main": "dist/index.js",
|
11
10
|
"files": [
|
12
|
-
"
|
13
|
-
"src"
|
11
|
+
"dist"
|
14
12
|
],
|
15
13
|
"author": "roma4ka",
|
16
14
|
"license": "ISC",
|
17
15
|
"dependencies": {
|
18
|
-
|
16
|
+
"@esbuild-plugins/node-resolve": "^0.1.4"
|
19
17
|
},
|
20
18
|
"devDependencies": {
|
21
19
|
"@testing-library/jest-dom": "^5.16.4",
|
@@ -23,6 +21,7 @@
|
|
23
21
|
"@testing-library/user-event": "^14.2.1",
|
24
22
|
"@types/node": "^18.0.0",
|
25
23
|
"@types/react": "^18.0.14",
|
24
|
+
"esbuild": "^0.15.1",
|
26
25
|
"jest": "^28.1.1",
|
27
26
|
"react": "^18.2.0",
|
28
27
|
"ts-jest": "^28.0.5",
|
package/index.d.ts
DELETED
@@ -1,6 +0,0 @@
|
|
1
|
-
import { createStore } from "./src/createStore";
|
2
|
-
import Provider from "./src/Provider";
|
3
|
-
import { useStore } from "./src/useStore";
|
4
|
-
export declare type createStore = typeof createStore;
|
5
|
-
export declare type Provider = typeof Provider;
|
6
|
-
export declare type useStore = typeof useStore;
|
package/index.js
DELETED
package/src/Store.js
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
-
};
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.Store = void 0;
|
7
|
-
const react_1 = __importDefault(require("react"));
|
8
|
-
const isEqual_1 = require("./isEqual");
|
9
|
-
class Store {
|
10
|
-
constructor(value, actions) {
|
11
|
-
this.listeners = [];
|
12
|
-
this.context = react_1.default.createContext(value);
|
13
|
-
this.value = value;
|
14
|
-
this.actions = actions;
|
15
|
-
}
|
16
|
-
update(callback) {
|
17
|
-
const newValue = callback(this.value);
|
18
|
-
if (!(0, isEqual_1.isEqual)(newValue, this.value)) {
|
19
|
-
this.value = newValue;
|
20
|
-
this.listeners.map(listener => listener.onUpdate());
|
21
|
-
}
|
22
|
-
}
|
23
|
-
action(callback) {
|
24
|
-
callback(this.actions);
|
25
|
-
}
|
26
|
-
subscribe(listener) {
|
27
|
-
this.listeners.push(listener);
|
28
|
-
}
|
29
|
-
unsubscribe(listener) {
|
30
|
-
this.listeners = this.listeners.filter(l => l !== listener);
|
31
|
-
}
|
32
|
-
}
|
33
|
-
exports.Store = Store;
|