react-app-store-manager 0.0.4 → 0.1.2
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 +22 -11
- package/dist/index.js +24 -23
- package/package.json +4 -1
- package/.idea/deployment.xml +0 -14
- package/.idea/jsLibraryMappings.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/react-app-store-manager.iml +0 -12
- package/tsconfig.json +0 -13
package/dist/index.d.ts
CHANGED
@@ -1,19 +1,30 @@
|
|
1
|
-
import React from "react";
|
1
|
+
import React, { ReactNode } from "react";
|
2
2
|
export declare function createStore<T>(defaultValue: T): StoreInterface<T>;
|
3
|
-
|
3
|
+
export declare function useStore<T>(store: StoreInterface<T>): T;
|
4
|
+
export interface StateProviderProps {
|
5
|
+
children: ReactNode;
|
6
|
+
store: StoreInterface<any>;
|
7
|
+
}
|
8
|
+
export declare const StateProvider: ({ children, store }: StateProviderProps) => JSX.Element;
|
9
|
+
declare type getFunction<S> = () => S;
|
10
|
+
declare type changeFunction<S> = (store: S) => S;
|
11
|
+
export interface StoreInterface<T> {
|
4
12
|
get(): T;
|
5
13
|
update(callback: (state: T) => T): void;
|
6
14
|
context: React.Context<any>;
|
7
|
-
getCallback
|
8
|
-
changeCallback
|
15
|
+
getCallback?: getFunction<T>;
|
16
|
+
changeCallback?: changeFunction<T>;
|
9
17
|
addListener(onGet: getFunction<T>, onChange: changeFunction<T>): void;
|
10
18
|
removeListener(): void;
|
11
19
|
}
|
12
|
-
declare
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
20
|
+
export declare class Store implements StoreInterface<any> {
|
21
|
+
context: React.Context<any>;
|
22
|
+
constructor(defaultValue: any);
|
23
|
+
getCallback?: getFunction<any>;
|
24
|
+
changeCallback?: changeFunction<any>;
|
25
|
+
get: () => any;
|
26
|
+
update: (callback: any) => any;
|
27
|
+
addListener(onGet: getFunction<any>, onChange: changeFunction<any>): void;
|
28
|
+
removeListener(): void;
|
29
|
+
}
|
19
30
|
export {};
|
package/dist/index.js
CHANGED
@@ -23,36 +23,23 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
23
23
|
return result;
|
24
24
|
};
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
26
|
-
exports.
|
26
|
+
exports.Store = exports.StateProvider = exports.useStore = exports.createStore = void 0;
|
27
27
|
var react_1 = __importStar(require("react"));
|
28
28
|
function createStore(defaultValue) {
|
29
29
|
return new Store(defaultValue);
|
30
30
|
}
|
31
31
|
exports.createStore = createStore;
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
this.update = function (callback) { return _this.changeCallback(callback); };
|
37
|
-
this.context = (0, react_1.createContext)(defaultValue);
|
38
|
-
}
|
39
|
-
Store.prototype.addListener = function (onGet, onChange) {
|
40
|
-
this.getCallback = onGet;
|
41
|
-
this.changeCallback = onChange;
|
42
|
-
};
|
43
|
-
Store.prototype.removeListener = function () {
|
44
|
-
this.getCallback = null;
|
45
|
-
this.changeCallback = null;
|
46
|
-
};
|
47
|
-
return Store;
|
48
|
-
}());
|
32
|
+
function useStore(store) {
|
33
|
+
return (0, react_1.useContext)(store.context);
|
34
|
+
}
|
35
|
+
exports.useStore = useStore;
|
49
36
|
var StateProvider = function (_a) {
|
50
37
|
var children = _a.children, store = _a.store;
|
51
38
|
// @ts-ignore
|
52
39
|
var _b = (0, react_1.useState)(store.context._currentValue), storeContent = _b[0], setStoreContent = _b[1];
|
53
40
|
var storeRef = (0, react_1.useRef)();
|
54
|
-
storeRef.current = storeContent;
|
55
41
|
(0, react_1.useMemo)(function () {
|
42
|
+
storeRef.current = storeContent;
|
56
43
|
store.addListener(function () { return storeRef.current; }, function (store) {
|
57
44
|
setStoreContent(store);
|
58
45
|
storeRef.current = store;
|
@@ -63,7 +50,21 @@ var StateProvider = function (_a) {
|
|
63
50
|
return (react_1.default.createElement(StoreContext.Provider, { value: storeContent }, children));
|
64
51
|
};
|
65
52
|
exports.StateProvider = StateProvider;
|
66
|
-
function
|
67
|
-
|
68
|
-
|
69
|
-
|
53
|
+
var Store = /** @class */ (function () {
|
54
|
+
function Store(defaultValue) {
|
55
|
+
var _this = this;
|
56
|
+
this.get = function () { return _this.getCallback && _this.getCallback(); };
|
57
|
+
this.update = function (callback) { return _this.changeCallback && _this.changeCallback(callback); };
|
58
|
+
this.context = (0, react_1.createContext)(defaultValue);
|
59
|
+
}
|
60
|
+
Store.prototype.addListener = function (onGet, onChange) {
|
61
|
+
this.getCallback = onGet;
|
62
|
+
this.changeCallback = onChange;
|
63
|
+
};
|
64
|
+
Store.prototype.removeListener = function () {
|
65
|
+
this.getCallback = undefined;
|
66
|
+
this.changeCallback = undefined;
|
67
|
+
};
|
68
|
+
return Store;
|
69
|
+
}());
|
70
|
+
exports.Store = Store;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "react-app-store-manager",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.1.2",
|
4
4
|
"description": "",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"types": "dist/index.d.ts",
|
@@ -13,5 +13,8 @@
|
|
13
13
|
"jest": "^28.1.1",
|
14
14
|
"react": "^18.2.0",
|
15
15
|
"ts-jest": "^28.0.5"
|
16
|
+
},
|
17
|
+
"devDependencies": {
|
18
|
+
"@types/react": "^18.0.14"
|
16
19
|
}
|
17
20
|
}
|
package/.idea/deployment.xml
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<project version="4">
|
3
|
-
<component name="PublishConfigData" remoteFilesAllowedToDisappearOnAutoupload="false">
|
4
|
-
<serverData>
|
5
|
-
<paths name="server">
|
6
|
-
<serverdata>
|
7
|
-
<mappings>
|
8
|
-
<mapping local="$PROJECT_DIR$" web="/" />
|
9
|
-
</mappings>
|
10
|
-
</serverdata>
|
11
|
-
</paths>
|
12
|
-
</serverData>
|
13
|
-
</component>
|
14
|
-
</project>
|
package/.idea/modules.xml
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<project version="4">
|
3
|
-
<component name="ProjectModuleManager">
|
4
|
-
<modules>
|
5
|
-
<module fileurl="file://$PROJECT_DIR$/.idea/react-app-store-manager.iml" filepath="$PROJECT_DIR$/.idea/react-app-store-manager.iml" />
|
6
|
-
</modules>
|
7
|
-
</component>
|
8
|
-
</project>
|
@@ -1,12 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<module type="WEB_MODULE" version="4">
|
3
|
-
<component name="NewModuleRootManager">
|
4
|
-
<content url="file://$MODULE_DIR$">
|
5
|
-
<excludeFolder url="file://$MODULE_DIR$/temp" />
|
6
|
-
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
|
7
|
-
<excludeFolder url="file://$MODULE_DIR$/tmp" />
|
8
|
-
</content>
|
9
|
-
<orderEntry type="inheritedJdk" />
|
10
|
-
<orderEntry type="sourceFolder" forTests="false" />
|
11
|
-
</component>
|
12
|
-
</module>
|
package/tsconfig.json
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"compilerOptions": {
|
3
|
-
"target": "es5",
|
4
|
-
"module": "commonjs",
|
5
|
-
"lib": ["es2017", "es7", "es6", "dom"],
|
6
|
-
"declaration": true,
|
7
|
-
"outDir": "dist",
|
8
|
-
"strict": true,
|
9
|
-
"esModuleInterop": true,
|
10
|
-
"jsx": "react",
|
11
|
-
},
|
12
|
-
"exclude": ["node_modules", "dist", "test"]
|
13
|
-
}
|