import SetPathStatus from './SetPathStatus' ; import { LocationState , State } from '../types' ; interface InitializePathArgs { location : LocationState ; bundle : any ; } /**
 * Run the "init" action if necessary once per page
 */ const InitializePath = ( state , { location , bundle } ) => { const { path } = location ; if ( state . paths [ path ] === 'ready' ) { return state ; } if ( typeof bundle ?. Init !== 'function' && typeof bundle ?. init !== 'function' ) { return SetPathStatus ( state , { path , status : 'ready' } ) ; } const PageInitAction = bundle ?. Init ?? bundle ?. init ; const action = PageInitAction ( state , location ) ; if ( Array . isArray ( action ) ) { const loadEffects = action . slice ( 1 ) . filter ( ( fx => fx [ 0 ] . fxName === 'loadStatic' ) ) ; if ( loadEffects . length > 0 ) { action [ 0 ] = SetPathStatus ( action [ 0 ] , { path , status : 'fetching' } ) ; loadEffects . forEach ( fx => fx [ 1 ] . path = path ) ; } return action ; } return SetPathStatus ( action , { path , status : 'ready' } ) ; } ; export default InitializePath ;