1- import produce from "immer" ;
2-
31export default function loading (
42 config = {
53 name : 'loading' ,
@@ -20,25 +18,23 @@ export default function loading(
2018 } ,
2119 reducers : {
2220 init ( state , action ) {
23- return produce ( state , draft => {
24- draft . epics = action . epics ;
25- } ) ;
21+ state . epics = action . epics ;
22+ return state ;
2623 } ,
2724 epicStart ( state , action ) {
28- return produce ( state , draft => {
29- const epicCounterKey = `${ action . epic } Counter` ;
30- let epicCounter = draft . epics [ action . model ] [ epicCounterKey ] + action . loading ;
25+ const epicCounterKey = `${ action . epic } Counter` ;
26+ let epicCounter = state . epics [ action . model ] [ epicCounterKey ] + action . loading ;
27+
28+ state . epics [ action . model ] [ epicCounterKey ] = epicCounter ;
29+ state . epics [ action . model ] [ action . epic ] = epicCounter > 0 ;
3130
32- draft . epics [ action . model ] [ epicCounterKey ] = epicCounter ;
33- draft . epics [ action . model ] [ action . epic ] = epicCounter > 0 ;
34- } ) ;
31+ return state ;
3532 } ,
3633 epicStop ( state , action ) {
37- return produce ( state , draft => {
38- const epicCounterKey = `${ action . epic } Counter` ;
39- draft . epics [ action . model ] [ epicCounterKey ] = 0 ;
40- draft . epics [ action . model ] [ action . epic ] = false ;
41- } ) ;
34+ const epicCounterKey = `${ action . epic } Counter` ;
35+ state . epics [ action . model ] [ epicCounterKey ] = 0 ;
36+ state . epics [ action . model ] [ action . epic ] = false ;
37+ return state ;
4238 } ,
4339 } ,
4440 } ;
@@ -63,19 +59,17 @@ export default function loading(
6359 model . reducers . loadingEnd = loadingEnd ;
6460
6561 function loadingStart ( state , { payload : { epic } } ) {
66- return produce ( state , draft => {
67- const epicCounterKey = `${ epic } Counter` ;
68- const epicCounter = draft . loading [ epicCounterKey ] + 1
69- draft . loading [ epicCounterKey ] = epicCounter ;
70- draft . loading [ epic ] = epicCounter > 0 ;
71- } ) ;
62+ const epicCounterKey = `${ epic } Counter` ;
63+ const epicCounter = state . loading [ epicCounterKey ] + 1
64+ state . loading [ epicCounterKey ] = epicCounter ;
65+ state . loading [ epic ] = epicCounter > 0 ;
66+ return state ;
7267 }
7368
7469 function loadingEnd ( state , { payload : { epic } } ) {
75- return produce ( state , draft => {
76- draft . loading [ `${ epic } Counter` ] = 0 ;
77- draft . loading [ epic ] = false ;
78- } ) ;
70+ state . loading [ `${ epic } Counter` ] = 0 ;
71+ state . loading [ epic ] = false ;
72+ return state ;
7973 }
8074 } ) ;
8175
0 commit comments