fix event passing

This commit is contained in:
Florian Dold 2016-09-23 18:28:50 +02:00
parent 5737c121ca
commit c590e03aea

View File

@ -97,13 +97,19 @@ namespace TalerNotify {
*/ */
function addHandler(type: string, handler: HandlerFn) { function addHandler(type: string, handler: HandlerFn) {
let handlerWrap = (e: CustomEvent) => { let handlerWrap = (e: CustomEvent) => {
let callId: number|undefined = e.detail.callId; if (e.type != type) {
throw Error(`invariant violated`);
}
let callId: number|undefined = undefined;
if (e.detail && e.detail.callId != undefined) {
callId = e.detail.callId;
}
let responder = (msg?: any) => { let responder = (msg?: any) => {
let fullMsg = Object.assign({}, msg, {callId}); let fullMsg = Object.assign({}, msg, {callId});
let evt = new CustomEvent(type + "-result", {detail: fullMsg}); let evt = new CustomEvent(type + "-result", {detail: fullMsg});
document.dispatchEvent(evt); document.dispatchEvent(evt);
}; };
handler(e, responder); handler(e.detail, responder);
}; };
document.addEventListener(type, handlerWrap); document.addEventListener(type, handlerWrap);
handlers.push({type, listener: handlerWrap}); handlers.push({type, listener: handlerWrap});
@ -149,6 +155,7 @@ namespace TalerNotify {
addHandler("taler-confirm-contract", (msg: any) => { addHandler("taler-confirm-contract", (msg: any) => {
console.log("got msg", msg);
if (!msg.contract_wrapper) { if (!msg.contract_wrapper) {
console.error("contract wrapper missing"); console.error("contract wrapper missing");
return; return;