750c1a03 by Adam Heath

Split index into astro+session.

1 parent 9aaa6cbf
......@@ -2,10 +2,11 @@
"name": "astro-redux",
"type": "module",
"exports": {
".": "./src/index.mjs",
"./astro": "./src/astro.mjs",
"./client": "./src/client.mjs",
"./slices": "./src/slices.mjs",
"./react": "./src/react.jsx",
"./session": "./src/session.jsx",
"./ReduxIsland": "./src/ReduxIsland.astro"
},
"sideEffects": [
......
import NodeCache from 'node-cache'
import { configureStore } from '@reduxjs/toolkit'
export const makeLeadingCase = (s) => s.substring(0, 1).toUpperCase() + s.substring(1)
export const fixUnsubscribe = async (store, action) => {
......@@ -41,21 +38,4 @@ export const createAstroApiWrappers = (apiWrappers) => Object.entries(apiWrapper
return result
}, {})
export const sessionStoreCache = new NodeCache({
stdTTL: 600, // in seconds
useClones: false,
})
export const createGetSessionStore = (storeConfig) => (session) => {
const getStore = (sessionId) => {
const currentStore = sessionStoreCache.get(sessionId)
if (currentStore) return currentStore
const newStore = configureStore(storeConfig)
sessionStoreCache.set(sessionId, newStore)
return newStore
}
const { id: sessionId } = session
return getStore(sessionId)
}
export { default as AstroReduxProvider } from './Provider.astro'
......
import NodeCache from 'node-cache'
import { configureStore } from '@reduxjs/toolkit'
export const sessionStoreCache = new NodeCache({
stdTTL: 600, // in seconds
useClones: false,
})
export const createGetSessionStore = (storeConfig) => (session) => {
const getStore = (sessionId) => {
const currentStore = sessionStoreCache.get(sessionId)
if (currentStore) return currentStore
const newStore = configureStore(storeConfig)
sessionStoreCache.set(sessionId, newStore)
return newStore
}
const { id: sessionId } = session
return getStore(sessionId)
}