@@ -2,23 +2,35 @@ import { createDataStore } from '@bigcommerce/data-store';
2
2
3
3
import { createRequestErrorFactory } from '../common/error' ;
4
4
5
+ import { CheckoutHydrateActionType } from './checkout-hydrate-actions' ;
6
+ import CheckoutInitialState from './checkout-initial-state' ;
5
7
import CheckoutStore , { CheckoutStoreOptions } from './checkout-store' ;
6
8
import CheckoutStoreState from './checkout-store-state' ;
7
9
import createActionTransformer from './create-action-transformer' ;
8
10
import createCheckoutStoreReducer from './create-checkout-store-reducer' ;
9
11
import { createInternalCheckoutSelectorsFactory } from './create-internal-checkout-selectors' ;
10
12
11
13
export default function createCheckoutStore (
12
- initialState : Partial < CheckoutStoreState > = { } ,
14
+ initialStoreState : Partial < CheckoutStoreState > = { } ,
15
+ initialServerState ?: CheckoutInitialState ,
13
16
options ?: CheckoutStoreOptions ,
14
17
) : CheckoutStore {
15
18
const actionTransformer = createActionTransformer ( createRequestErrorFactory ( ) ) ;
16
19
const createInternalCheckoutSelectors = createInternalCheckoutSelectorsFactory ( ) ;
17
20
const stateTransformer = ( state : CheckoutStoreState ) => createInternalCheckoutSelectors ( state ) ;
21
+ const reducer = createCheckoutStoreReducer ( ) ;
22
+ const hydrateAction = {
23
+ type : CheckoutHydrateActionType . HydrateInitialState ,
24
+ payload : initialServerState ,
25
+ } ;
18
26
19
- return createDataStore ( createCheckoutStoreReducer ( ) , initialState , {
20
- actionTransformer,
21
- stateTransformer,
22
- ...options ,
23
- } ) ;
27
+ return createDataStore (
28
+ reducer ,
29
+ reducer ( initialStoreState as CheckoutStoreState , hydrateAction ) ,
30
+ {
31
+ actionTransformer,
32
+ stateTransformer,
33
+ ...options ,
34
+ } ,
35
+ ) ;
24
36
}
0 commit comments