UNPKG

@wordpress/e2e-tests

Version:
61 lines (52 loc) 1.22 kB
/** * WordPress dependencies */ import { store, withSyncEvent, getContext } from '@wordpress/interactivity'; const { state } = store( 'router', { state: { status: 'idle', navigations: { pending: 0, count: 0, }, timeout: 10000, data: { get getterProp() { return `value from getter (${ state.data.prop1 })`; }, }, }, actions: { navigate: withSyncEvent( function* ( e ) { e.preventDefault(); state.navigations.count += 1; state.navigations.pending += 1; state.status = 'busy'; const force = e.target.dataset.forceNavigation === 'true'; const { timeout } = state; const { actions } = yield import( '@wordpress/interactivity-router' ); try { yield actions.navigate( e.target.href, { force, timeout } ); } catch ( error ) { state.status = 'fail'; } state.navigations.pending -= 1; if ( state.navigations.pending === 0 && state.status === 'busy' ) { state.status = 'idle'; } } ), toggleTimeout() { state.timeout = state.timeout === 10000 ? 0 : 10000; }, }, } ); store( 'router/derived-state', { state: { get derivedStateClosure() { const { value } = getContext(); return `${ value }FromGetter`; }, }, } );