react-app-store-manager 0.0.1 → 0.0.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.
File without changes
|
package/package.json
CHANGED
@@ -1,10 +1,14 @@
|
|
1
1
|
{
|
2
2
|
"name": "react-app-store-manager",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.2",
|
4
4
|
"description": "",
|
5
|
-
"main": "
|
5
|
+
"main": "dist/index.js",
|
6
|
+
"module": "dist/index.js",
|
7
|
+
"files": [
|
8
|
+
"dist/"
|
9
|
+
],
|
6
10
|
"scripts": {
|
7
|
-
"build": "babel src --out-dir
|
11
|
+
"build": "babel src --out-dir dist --copy-files"
|
8
12
|
},
|
9
13
|
"author": "",
|
10
14
|
"license": "ISC",
|
@@ -14,7 +18,6 @@
|
|
14
18
|
"@babel/preset-env": "^7.18.2"
|
15
19
|
},
|
16
20
|
"dependencies": {
|
17
|
-
"react": "^18.2.0"
|
18
|
-
"react-app-store-manager": "^1.0.0"
|
21
|
+
"react": "^18.2.0"
|
19
22
|
}
|
20
23
|
}
|
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/src/StoreManager.tsx
DELETED
@@ -1,76 +0,0 @@
|
|
1
|
-
import React, {createContext, useContext, useMemo, useRef, useState} from "react";
|
2
|
-
|
3
|
-
export function createStore<T>(defaultValue: T) : StoreInterface<T> {
|
4
|
-
return new Store(defaultValue)
|
5
|
-
}
|
6
|
-
|
7
|
-
interface StoreInterface<T> {
|
8
|
-
get() : T
|
9
|
-
update(callback : (state: T) => T) : void
|
10
|
-
|
11
|
-
context: React.Context<any>
|
12
|
-
|
13
|
-
getCallback: getFunction<T>
|
14
|
-
changeCallback: changeFunction<T>
|
15
|
-
|
16
|
-
addListener(onGet : getFunction<T>,onChange : changeFunction<T>): void;
|
17
|
-
removeListener() : void
|
18
|
-
}
|
19
|
-
|
20
|
-
type getFunction<S> = () => S
|
21
|
-
type changeFunction<S> = (store: S) => S
|
22
|
-
|
23
|
-
class Store implements StoreInterface<any> {
|
24
|
-
|
25
|
-
context
|
26
|
-
|
27
|
-
constructor(defaultValue: any) {
|
28
|
-
this.context = createContext(defaultValue)
|
29
|
-
}
|
30
|
-
|
31
|
-
getCallback: any
|
32
|
-
changeCallback: any
|
33
|
-
|
34
|
-
get = () => this.getCallback()
|
35
|
-
|
36
|
-
update = (callback: any) => this.changeCallback(callback)
|
37
|
-
|
38
|
-
addListener(onGet : getFunction<any>,onChange : changeFunction<any>) : void {
|
39
|
-
this.getCallback = onGet
|
40
|
-
this.changeCallback = onChange
|
41
|
-
}
|
42
|
-
removeListener() {
|
43
|
-
this.getCallback = null
|
44
|
-
this.changeCallback = null
|
45
|
-
}
|
46
|
-
}
|
47
|
-
|
48
|
-
export const StateProvider = ({children,store} : {children: any,store: StoreInterface<any>}) => {
|
49
|
-
// @ts-ignore
|
50
|
-
const [storeContent,setStoreContent] = useState(store.context._currentValue)
|
51
|
-
const storeRef = useRef()
|
52
|
-
|
53
|
-
storeRef.current = storeContent
|
54
|
-
|
55
|
-
useMemo(() => {
|
56
|
-
store.addListener(() => storeRef.current,(store) => {
|
57
|
-
setStoreContent(store)
|
58
|
-
storeRef.current = store
|
59
|
-
})
|
60
|
-
|
61
|
-
return () => store.removeListener()
|
62
|
-
},[store])
|
63
|
-
|
64
|
-
const StoreContext = store.context
|
65
|
-
return (
|
66
|
-
<StoreContext.Provider
|
67
|
-
value={storeContent}
|
68
|
-
>
|
69
|
-
{children}
|
70
|
-
</StoreContext.Provider>
|
71
|
-
)
|
72
|
-
}
|
73
|
-
|
74
|
-
export function useStore<T>(store: StoreInterface<T>) {
|
75
|
-
return useContext<T>(store.context)
|
76
|
-
}
|