| 1 |
/** |
| 2 |
* Internal dependencies |
| 3 |
*/ |
| 4 |
import { SET_PRELOAD_STATUS, PRELOADER_START, PRELOADER_CANCEL } from './actions'; |
| 5 |
import { PreloadId } from '../preload-id'; |
| 6 |
|
| 7 |
const DEFAULT_STATE = { |
| 8 |
isPreloading: false, |
| 9 |
cacheCount: 0, |
| 10 |
progressPercent: 0, |
| 11 |
source: '', |
| 12 |
preloadId: '', |
| 13 |
notice: { |
| 14 |
type: '', |
| 15 |
code: '', |
| 16 |
message: '', |
| 17 |
}, |
| 18 |
}; |
| 19 |
|
| 20 |
const reducer = ( state = DEFAULT_STATE, action ) => { |
| 21 |
switch (action.type) { |
| 22 |
case SET_PRELOAD_STATUS: |
| 23 |
// Clear the preload ID while preloading, so the final notice can be sent. |
| 24 |
if (action.newState.isPreloading) { |
| 25 |
PreloadId.clear(); |
| 26 |
} |
| 27 |
|
| 28 |
return { |
| 29 |
...state, |
| 30 |
...action.newState, |
| 31 |
}; |
| 32 |
case PRELOADER_START: |
| 33 |
return { |
| 34 |
...state, |
| 35 |
isPreloading: true, |
| 36 |
notice: action.notice, |
| 37 |
}; |
| 38 |
case PRELOADER_CANCEL: |
| 39 |
return { |
| 40 |
...state, |
| 41 |
isPreloading: false, |
| 42 |
notice: action.notice, |
| 43 |
}; |
| 44 |
default: |
| 45 |
return state; |
| 46 |
} |
| 47 |
}; |
| 48 |
|
| 49 |
export default reducer; |
| 50 |
|