2020-03-10 13:39:21 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2020-04-03 11:50:54 +00:00
|
|
|
import {
|
|
|
|
emitterCallback,
|
|
|
|
reducer,
|
|
|
|
emitEvent,
|
|
|
|
emitEventWithAbort,
|
2020-07-30 10:57:22 +00:00
|
|
|
} from '../../shared/event-emit';
|
2020-03-10 13:39:21 +00:00
|
|
|
|
|
|
|
const EMIT_TYPES = {
|
2020-04-14 16:52:23 +00:00
|
|
|
CHECKOUT_BEFORE_PROCESSING: 'checkout_before_processing',
|
|
|
|
CHECKOUT_AFTER_PROCESSING_WITH_SUCCESS:
|
|
|
|
'checkout_after_processing_with_success',
|
|
|
|
CHECKOUT_AFTER_PROCESSING_WITH_ERROR:
|
|
|
|
'checkout_after_processing_with_error',
|
2020-03-10 13:39:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Receives a reducer dispatcher and returns an object with the
|
2020-04-14 16:52:23 +00:00
|
|
|
* callback registration function for the checkout emit
|
2020-03-10 13:39:21 +00:00
|
|
|
* events.
|
|
|
|
*
|
|
|
|
* Calling the event registration function with the callback will register it
|
|
|
|
* for the event emitter and will return a dispatcher for removing the
|
|
|
|
* registered callback (useful for implementation in `useEffect`).
|
|
|
|
*
|
|
|
|
* @param {Function} dispatcher The emitter reducer dispatcher.
|
|
|
|
*
|
2020-04-14 16:52:23 +00:00
|
|
|
* @return {Object} An object with the checkout emmitter registration
|
2020-03-10 13:39:21 +00:00
|
|
|
*/
|
|
|
|
const emitterSubscribers = ( dispatcher ) => ( {
|
2020-04-14 16:52:23 +00:00
|
|
|
onCheckoutAfterProcessingWithSuccess: emitterCallback(
|
|
|
|
EMIT_TYPES.CHECKOUT_AFTER_PROCESSING_WITH_SUCCESS,
|
2020-04-03 11:50:54 +00:00
|
|
|
dispatcher
|
|
|
|
),
|
2020-04-14 16:52:23 +00:00
|
|
|
onCheckoutAfterProcessingWithError: emitterCallback(
|
|
|
|
EMIT_TYPES.CHECKOUT_AFTER_PROCESSING_WITH_ERROR,
|
2020-04-03 11:50:54 +00:00
|
|
|
dispatcher
|
|
|
|
),
|
2020-04-14 16:52:23 +00:00
|
|
|
onCheckoutBeforeProcessing: emitterCallback(
|
|
|
|
EMIT_TYPES.CHECKOUT_BEFORE_PROCESSING,
|
2020-04-03 11:50:54 +00:00
|
|
|
dispatcher
|
|
|
|
),
|
2020-03-10 13:39:21 +00:00
|
|
|
} );
|
|
|
|
|
2020-03-20 16:46:24 +00:00
|
|
|
export {
|
|
|
|
EMIT_TYPES,
|
|
|
|
emitterSubscribers,
|
|
|
|
reducer,
|
|
|
|
emitEvent,
|
|
|
|
emitEventWithAbort,
|
|
|
|
};
|