@@ -4,6 +4,7 @@ import { createBrowserHistory } from 'history';
44import { configureStore } from './store/store' ;
55import { clearActionsCache } from './store/actions' ;
66import { createActionSequences } from './store/sequences' ;
7+ import { createInitialState } from './store/state' ;
78
89import PageRouter from './components/PageRouter' ;
910import StartWrapper from './components/StartWrapper' ;
@@ -18,12 +19,10 @@ if (process.env.NODE_ENV !== 'production') {
1819 PageComposer = require ( './components/PageComposer/PageComposer' ) . default ;
1920}
2021
21- let store ;
22- let history ;
23-
24- export const initStore = ( name , version , initialState = { } ) => {
25- history = createBrowserHistory ( ) ;
26- store = configureStore ( initialState , { history } , { name, version } ) ;
22+ const initStore = ( pages , name , version ) => {
23+ const initialState = createInitialState ( pages ) ;
24+ const history = createBrowserHistory ( ) ;
25+ const store = configureStore ( initialState , { history } , { name, version } ) ;
2726
2827 if ( process . env . NODE_ENV !== 'production' ) {
2928 window . __sendFrameworkMessage = ( message ) => {
@@ -82,12 +81,7 @@ class Application extends React.Component {
8281 } ;
8382
8483 render ( ) {
85- if ( ! store ) {
86- return (
87- < WarningComponent message = "Redux store is not initialized." />
88- ) ;
89- }
90- const { schema, userComponents, userFunctions } = this . props ;
84+ const { schema, userComponents, userFunctions, name, version } = this . props ;
9185 if ( process . env . NODE_ENV !== 'production' ) {
9286 const href = window . location . href ;
9387 if ( href . indexOf ( '/webcodesk__component_view' ) > 0 ) {
@@ -100,8 +94,15 @@ class Application extends React.Component {
10094 )
10195 }
10296 }
103- clearActionsCache ( ) ;
10497 const { routes, pages, flows } = schema ;
98+ const { store, history } = initStore ( pages , name , version ) ;
99+ if ( ! store ) {
100+ return (
101+ < WarningComponent message = "Redux store is not initialized." />
102+ ) ;
103+ }
104+ window . __applicationBrowserHistory = history ;
105+ clearActionsCache ( ) ;
105106 const { actionSequences, targetProperties } = createActionSequences ( flows , userFunctions ) ;
106107 // store action sequences and components properties in case we have to send them for debug
107108 this . actionSequences = actionSequences ;
0 commit comments