const addDns = ( domainName, record ) => ( dispatch, getState ) => { dispatch( { type: DOMAINS_DNS_ADD, domainName, record } ); const dns = getDomainDns( getState(), domainName ); const addResult = wpcom.undocumented().updateDns( domainName, dns.records ); addResult.then( () => dispatch( { type: DOMAINS_DNS_ADD_COMPLETED, domainName, record } ), () => dispatch( { type: DOMAINS_DNS_ADD_FAILED, domainName, record } ) ); return addResult; }
const receivedTwoFactorPushNotificationApproved = ( tokenLinks ) => ( dispatch ) => { if ( ! Array.isArray( tokenLinks ) ) { return dispatch( { type: TWO_FACTOR_AUTHENTICATION_PUSH_POLL_COMPLETED } ); } remoteLoginUser( tokenLinks ).then( () => dispatch( { type: TWO_FACTOR_AUTHENTICATION_PUSH_POLL_COMPLETED } ) ); }
compose( withSelect( ( select ) => ( { isOpen: select( 'automattic/starter-page-layouts' ).isOpen(), } ) ), withDispatch( ( dispatch ) => ( { setIsOpen: dispatch( 'automattic/starter-page-layouts' ).setIsOpen, } ) ) )( SidebarModalOpener )
lab.test('it handles a GET_DETAILS action', (done) => { Store.dispatch({ type: Constants.GET_DETAILS }); const state = Store.getState().details; Code.expect(state.loading).to.be.true(); Code.expect(state.hydrated).to.be.false(); done(); });
function isFormValid( store ) { const customerName = store.selectors.getCustomerName( store.getState() ); if ( ! customerName?.value.length ) { // Touch the field so it displays a validation error store.dispatch( store.actions.changeCustomerName( '' ) ); return false; } return true; }
render () { if (this.state.status !== States.CONNECTED) { return ( <Loading /> ); } return ( <Home items={this.state.items} dispatch={(k, v) => this.dispatch(k, v)} /> ); }
export function upload( context, next ) { // Store previous path to return to only if it was main showcase page if ( startsWith( context.prevPath, '/themes' ) && ! startsWith( context.prevPath, '/themes/upload' ) ) { context.store.dispatch( setBackPath( context.prevPath ) ); } context.primary = <Upload />; next(); }
// example of a thunk using the redux-thunk middleware export function saveFuelSavings(settings) { return function (dispatch) { // thunks allow for pre-processing actions, calling apis, and dispatching multiple actions // in this case at this point we could call a service that would persist the fuel savings return dispatch({ type: types.SAVE_FUEL_SAVINGS, dateModified: getFormattedDateTime(), settings }); }; }
const updateApprovals = ( { dispatch }, { noteId } ) => { const approvalTimers = timers.localApprovals; // local override should be a sliding window // so update time if it's still counting down if ( approvalTimers.hasOwnProperty( noteId ) ) { clearTimeout( approvalTimers[ noteId ] ); } approvalTimers[ noteId ] = setTimeout( () => dispatch( actions.notes.resetLocalApproval( noteId ) ), LOCAL_ACTION_PERSISTENCE ); }
lab.test('it calls dispatch from hidePasswordSaveSuccess', (done) => { stub.Store.dispatch.mock = function (action) { if (action.type === Constants.HIDE_PASSWORD_SAVE_SUCCESS) { done(); } }; Actions.hidePasswordSaveSuccess(); });
static hideDetailsSaveSuccess() { Store.dispatch({ type: Constants.HIDE_DETAILS_SAVE_SUCCESS }); }
export function reloadPost( post ) { return function ( dispatch ) { // keep track of any railcars we might have const railcar = post.railcar; const postKey = keyForPost( post ); fetchForKey( postKey ).then( ( data ) => { data.railcar = railcar; dispatch( receivePosts( [ data ] ) ); } ); }; }
// Log out user and remove token from localStorage export function logout() { return dispatch => { logoutUnsetUserLocalStorageAndCookie() dispatch({ type: LOGOUT }) } }
static showCreateNew(data) { Store.dispatch({ type: Constants.SHOW_CREATE_NEW }); }