@inglorious/react-store 3.0.2 → 5.0.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/package.json +2 -2
- package/src/index.jsx +13 -49
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inglorious/react-store",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "Official React bindings for @inglorious/store. Provides hooks and a Provider to connect your React components to the store.",
|
|
5
5
|
"author": "IceOnFire <antony.mistretta@gmail.com> (https://ingloriouscoderz.it)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"react": "^19.2.0",
|
|
43
|
-
"@inglorious/store": "
|
|
43
|
+
"@inglorious/store": "6.0.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"prettier": "^3.6.2",
|
package/src/index.jsx
CHANGED
|
@@ -1,49 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
return { Provider: StoreProvider, useSelector, useNotify }
|
|
15
|
-
|
|
16
|
-
function StoreProvider({ children }) {
|
|
17
|
-
return <Provider store={store}>{children}</Provider>
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function useNotify() {
|
|
21
|
-
return useCallback((type, payload) => {
|
|
22
|
-
store.notify(type, payload)
|
|
23
|
-
|
|
24
|
-
if (config.mode === "eager") {
|
|
25
|
-
sendAction({ type, payload }, store.getState())
|
|
26
|
-
}
|
|
27
|
-
}, [])
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function loop(store, config) {
|
|
32
|
-
const fps = config.fps ?? DEFAULT_FPS
|
|
33
|
-
|
|
34
|
-
setInterval(() => {
|
|
35
|
-
const processedEvents = store.update()
|
|
36
|
-
const skippedEvents = config.skippedEvents ?? []
|
|
37
|
-
|
|
38
|
-
const eventsToLog = processedEvents.filter(
|
|
39
|
-
({ type }) => !skippedEvents.includes(type),
|
|
40
|
-
)
|
|
41
|
-
if (eventsToLog.length) {
|
|
42
|
-
const action = {
|
|
43
|
-
type: eventsToLog.map(({ type }) => type).join("|"),
|
|
44
|
-
payload: eventsToLog,
|
|
45
|
-
}
|
|
46
|
-
sendAction(action, store.getState())
|
|
47
|
-
}
|
|
48
|
-
}, ONE_SECOND / fps)
|
|
49
|
-
}
|
|
1
|
+
import { Provider, useSelector } from "react-redux"
|
|
2
|
+
|
|
3
|
+
export function createReactStore(store) {
|
|
4
|
+
function StoreProvider({ children }) {
|
|
5
|
+
return <Provider store={store}>{children}</Provider>
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function useNotify() {
|
|
9
|
+
return store._api.notify
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return { Provider: StoreProvider, useSelector, useNotify }
|
|
13
|
+
}
|