diff --git a/javascript/callbacks.js b/javascript/callbacks.js index 63f2ca2a..af52a1bd 100644 --- a/javascript/callbacks.js +++ b/javascript/callbacks.js @@ -12,6 +12,7 @@ export const beforeDOMUpdate = event => { const reflexElement = XPathToElement(xpathElement) const reflex = reflexes[reflexId] const promise = reflex.promise + const payload = event.detail.payload reflex.pendingOperations-- @@ -23,7 +24,7 @@ export const beforeDOMUpdate = event => { element: reflexElement, event, data: promise.data, - payload: event.detail.payload + payload }) ) @@ -32,7 +33,8 @@ export const beforeDOMUpdate = event => { 'success', reflexElement, controllerElement, - reflexId + reflexId, + payload ) ) } @@ -45,6 +47,7 @@ export const afterDOMUpdate = event => { const reflexElement = XPathToElement(xpathElement) const reflex = reflexes[reflexId] const promise = reflex.promise + const payload = event.detail.payload reflex.completedOperations++ @@ -58,7 +61,7 @@ export const afterDOMUpdate = event => { element: reflexElement, event, data: promise.data, - payload: event.detail.payload + payload }) ) @@ -67,7 +70,8 @@ export const afterDOMUpdate = event => { 'finalize', reflexElement, controllerElement, - reflexId + reflexId, + payload ) ) } @@ -80,6 +84,7 @@ export const serverMessage = event => { const reflexElement = XPathToElement(xpathElement) const promise = reflexes[reflexId].promise const subjects = { error: true, halted: true, nothing: true, success: true } + const payload = event.detail.payload controllerElement.reflexError = controllerElement.reflexError || {} @@ -91,7 +96,7 @@ export const serverMessage = event => { element: reflexElement, event, toString: () => body, - payload: event.detail.payload + payload }) reflexes[reflexId].finalStage = subject === 'halted' ? 'halted' : 'after' @@ -99,5 +104,11 @@ export const serverMessage = event => { if (Debug.enabled) Log[subject === 'error' ? 'error' : 'success'](event) if (subjects[subject]) - dispatchLifecycleEvent(subject, reflexElement, controllerElement, reflexId) + dispatchLifecycleEvent( + subject, + reflexElement, + controllerElement, + reflexId, + payload + ) } diff --git a/javascript/lifecycle.js b/javascript/lifecycle.js index 5f536def..1ae0d993 100644 --- a/javascript/lifecycle.js +++ b/javascript/lifecycle.js @@ -22,7 +22,8 @@ const invokeLifecycleMethod = ( stage, reflexElement, controllerElement, - reflexId + reflexId, + payload ) => { if (!controllerElement || !controllerElement.reflexData[reflexId]) return @@ -50,7 +51,8 @@ const invokeLifecycleMethod = ( reflexElement, reflex, controllerElement.reflexError[reflexId], - reflexId + reflexId, + payload ) } @@ -60,7 +62,8 @@ const invokeLifecycleMethod = ( reflexElement, reflex, controllerElement.reflexError[reflexId], - reflexId + reflexId, + payload ) } @@ -79,7 +82,8 @@ document.addEventListener( 'before', event.detail.element, event.detail.controller.element, - event.detail.reflexId + event.detail.reflexId, + event.detail.payload ), true ) @@ -91,13 +95,15 @@ document.addEventListener( 'success', event.detail.element, event.detail.controller.element, - event.detail.reflexId + event.detail.reflexId, + event.detail.payload ) dispatchLifecycleEvent( 'after', event.detail.element, event.detail.controller.element, - event.detail.reflexId + event.detail.reflexId, + event.detail.payload ) }, true @@ -110,13 +116,15 @@ document.addEventListener( 'success', event.detail.element, event.detail.controller.element, - event.detail.reflexId + event.detail.reflexId, + event.detail.payload ) dispatchLifecycleEvent( 'after', event.detail.element, event.detail.controller.element, - event.detail.reflexId + event.detail.reflexId, + event.detail.payload ) }, true @@ -129,13 +137,15 @@ document.addEventListener( 'error', event.detail.element, event.detail.controller.element, - event.detail.reflexId + event.detail.reflexId, + event.detail.payload ) dispatchLifecycleEvent( 'after', event.detail.element, event.detail.controller.element, - event.detail.reflexId + event.detail.reflexId, + event.detail.payload ) }, true @@ -148,7 +158,8 @@ document.addEventListener( 'halted', event.detail.element, event.detail.controller.element, - event.detail.reflexId + event.detail.reflexId, + event.detail.payload ), true ) @@ -160,7 +171,8 @@ document.addEventListener( 'after', event.detail.element, event.detail.controller.element, - event.detail.reflexId + event.detail.reflexId, + event.detail.payload ), true ) @@ -172,7 +184,8 @@ document.addEventListener( 'finalize', event.detail.element, event.detail.controller.element, - event.detail.reflexId + event.detail.reflexId, + event.detail.payload ), true ) @@ -197,7 +210,8 @@ export const dispatchLifecycleEvent = ( stage, reflexElement, controllerElement, - reflexId + reflexId, + payload ) => { if (!controllerElement) { if (Debug.enabled && !reflexes[reflexId].warned) { @@ -230,7 +244,8 @@ export const dispatchLifecycleEvent = ( reflex: target, controller, reflexId, - element: reflexElement + element: reflexElement, + payload } controllerElement.dispatchEvent( diff --git a/javascript/reflexes.js b/javascript/reflexes.js index 9c995a37..00b932be 100644 --- a/javascript/reflexes.js +++ b/javascript/reflexes.js @@ -57,12 +57,15 @@ export const performOperations = data => { reflexData = operation[0].detail ? operation[0].detail.stimulusReflex : operation[0].stimulusReflex + reflexData.payload = operation[0].detail + ? operation[0].detail.payload + : operation[0].payload } } }) if (reflexData) { - const { reflexId } = reflexData + const { reflexId, payload } = reflexData if (!reflexes[reflexId] && isolationMode.disabled) { const controllerElement = XPathToElement(reflexData.xpathController) @@ -84,7 +87,8 @@ export const performOperations = data => { 'before', reflexElement, controllerElement, - reflexId + reflexId, + payload ) registerReflex(reflexData) }