-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
9 changed files
with
95 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import * as React from 'react' | ||
|
||
import { | ||
persistStore, | ||
persistReducer, | ||
Persistor, | ||
FLUSH, | ||
REHYDRATE, | ||
PAUSE, | ||
PERSIST, | ||
PURGE, | ||
REGISTER | ||
} from 'redux-persist' | ||
import { PersistGate } from 'redux-persist/integration/react' | ||
import storage from 'redux-persist/lib/storage' | ||
import { configureStore } from '@reduxjs/toolkit' | ||
|
||
import reducers from 'core/features' | ||
import { Config, Toc } from 'core/types' | ||
import dynamic from 'next/dynamic' | ||
import { Provider } from 'react-redux' | ||
import { Story } from 'core/components' | ||
import StoryContainer from 'core/containers/story-container' | ||
|
||
export interface StoreProps { | ||
config: Config | ||
toc: Toc | ||
} | ||
export const StoryContext = React.createContext<Partial<ContextProps>>({}) | ||
|
||
type ContextProps = { | ||
persistor: Persistor | ||
config: Config | ||
} | ||
|
||
const StoreContainer = ({ config, toc }: StoreProps): JSX.Element => { | ||
const persistConfig = { | ||
key: config.identifier, | ||
storage: storage, | ||
blacklist: ['config'] | ||
} | ||
const persistedReducers = persistReducer(persistConfig, reducers) | ||
const store = configureStore({ | ||
reducer: persistedReducers, | ||
middleware: (getDefaultMiddleware) => | ||
getDefaultMiddleware({ | ||
serializableCheck: { | ||
ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER] | ||
}, | ||
thunk: { | ||
extraArgument: { config } | ||
} | ||
}), | ||
preloadedState: { | ||
navigation: { | ||
past: [], | ||
present: { toc }, | ||
future: [] | ||
}, | ||
choices: { | ||
past: [], | ||
present: {}, | ||
future: [] | ||
} | ||
}, | ||
devTools: true | ||
}) | ||
const persistor = persistStore(store) | ||
|
||
const Index = dynamic(() => import(`../../stories/${config.identifier}/index`)) | ||
|
||
return ( | ||
<Provider store={store}> | ||
<PersistGate persistor={persistor}> | ||
<StoryContainer config={config}> | ||
<StoryContext.Provider value={{ persistor, config }}> | ||
<Index> | ||
<Story story={config.identifier} /> | ||
</Index> | ||
</StoryContext.Provider> | ||
</StoryContainer> | ||
</PersistGate> | ||
</Provider> | ||
) | ||
} | ||
export default StoreContainer |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters