750c1a03 by Adam Heath

Split index into astro+session.

1 parent 9aaa6cbf
...@@ -2,10 +2,11 @@ ...@@ -2,10 +2,11 @@
2 "name": "astro-redux", 2 "name": "astro-redux",
3 "type": "module", 3 "type": "module",
4 "exports": { 4 "exports": {
5 ".": "./src/index.mjs", 5 "./astro": "./src/astro.mjs",
6 "./client": "./src/client.mjs", 6 "./client": "./src/client.mjs",
7 "./slices": "./src/slices.mjs", 7 "./slices": "./src/slices.mjs",
8 "./react": "./src/react.jsx", 8 "./react": "./src/react.jsx",
9 "./session": "./src/session.jsx",
9 "./ReduxIsland": "./src/ReduxIsland.astro" 10 "./ReduxIsland": "./src/ReduxIsland.astro"
10 }, 11 },
11 "sideEffects": [ 12 "sideEffects": [
......
1 import NodeCache from 'node-cache'
2 import { configureStore } from '@reduxjs/toolkit'
3
4 export const makeLeadingCase = (s) => s.substring(0, 1).toUpperCase() + s.substring(1) 1 export const makeLeadingCase = (s) => s.substring(0, 1).toUpperCase() + s.substring(1)
5 2
6 export const fixUnsubscribe = async (store, action) => { 3 export const fixUnsubscribe = async (store, action) => {
...@@ -41,21 +38,4 @@ export const createAstroApiWrappers = (apiWrappers) => Object.entries(apiWrapper ...@@ -41,21 +38,4 @@ export const createAstroApiWrappers = (apiWrappers) => Object.entries(apiWrapper
41 return result 38 return result
42 }, {}) 39 }, {})
43 40
44 export const sessionStoreCache = new NodeCache({
45 stdTTL: 600, // in seconds
46 useClones: false,
47 })
48
49 export const createGetSessionStore = (storeConfig) => (session) => {
50 const getStore = (sessionId) => {
51 const currentStore = sessionStoreCache.get(sessionId)
52 if (currentStore) return currentStore
53 const newStore = configureStore(storeConfig)
54 sessionStoreCache.set(sessionId, newStore)
55 return newStore
56 }
57 const { id: sessionId } = session
58 return getStore(sessionId)
59 }
60
61 export { default as AstroReduxProvider } from './Provider.astro' 41 export { default as AstroReduxProvider } from './Provider.astro'
......
1 import NodeCache from 'node-cache'
2 import { configureStore } from '@reduxjs/toolkit'
3
4 export const sessionStoreCache = new NodeCache({
5 stdTTL: 600, // in seconds
6 useClones: false,
7 })
8
9 export const createGetSessionStore = (storeConfig) => (session) => {
10 const getStore = (sessionId) => {
11 const currentStore = sessionStoreCache.get(sessionId)
12 if (currentStore) return currentStore
13 const newStore = configureStore(storeConfig)
14 sessionStoreCache.set(sessionId, newStore)
15 return newStore
16 }
17 const { id: sessionId } = session
18 return getStore(sessionId)
19 }
20