@@ -115,6 +115,7 @@ const createFetchableReducers = ({
115115 successField,
116116 overrides,
117117 updater,
118+ initialValue,
118119} ) => {
119120 const defaultReducers = {
120121 [ types . loading ] : state => ( {
@@ -144,7 +145,7 @@ const createFetchableReducers = ({
144145 [ types . clear ] : state => ( {
145146 ...state ,
146147 [ successField ] : {
147- ... state [ successField ] ,
148+ data : initialValue ,
148149 status : FETCHABLE_STATUS . INITIAL ,
149150 error : null ,
150151 } ,
@@ -171,7 +172,12 @@ const createFetchableAction = types => {
171172 return action ;
172173} ;
173174
174- export function handleFetchableAction ( args , actionName , modelName ) {
175+ export function handleFetchableAction ( {
176+ args,
177+ actionName,
178+ modelName,
179+ initialState,
180+ } ) {
175181 const typePrefix = `${ modelName } /${ actionName } ` ;
176182
177183 const t = {
@@ -190,14 +196,21 @@ export function handleFetchableAction(args, actionName, modelName) {
190196 // User can either provide only reducer field name for success case
191197 // or reducer overrides for `loading` / `success` / `failure` cases
192198 const successField = args . length > 0 ? args [ 0 ] : null ;
193- const overrides = args . length > 1 ? args [ 1 ] || { } : { } ;
194- const updater = args . length > 2 ? args [ 2 ] : defaultDataUpdater ;
195199
196200 // If no success field is provided -> create reducers for for tracking
197201 // the status and error of the fetchable action
202+
203+ /* eslint-disable indent */
198204 const reducers = successField
199- ? createFetchableReducers ( { types : t , successField, overrides, updater } )
205+ ? createFetchableReducers ( {
206+ types : t ,
207+ successField,
208+ overrides : args . length > 1 ? args [ 1 ] || { } : { } ,
209+ updater : args . length > 2 ? args [ 2 ] : defaultDataUpdater ,
210+ initialValue : initialState [ successField ] . data ,
211+ } )
200212 : createSimpleFetchableReducers ( { types : t , actionName } ) ;
213+ /* eslint-enable indent */
201214
202215 // Return types that are inlined to the other types instead of accessing them
203216 // via `types.fetchSomething.success` you access them normally
0 commit comments