Skip to content

Commit

Permalink
Fix bridge cleanup logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Brain committed Nov 7, 2017
1 parent 11d6d0e commit 2f9dbc3
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions src/bridge/parent.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,31 +125,24 @@ export function openBridge(url : string, domain : string) : ZalgoPromise<CrossDo

return documentBodyReady.then(body => {

return new ZalgoPromise((resolve, reject) => {

setTimeout(resolve, 1);

}).then(() => {
body.appendChild(iframe);

body.appendChild(iframe);
let bridge = iframe.contentWindow;

let bridge = iframe.contentWindow;
listenForRegister(bridge, domain);

listenForRegister(bridge, domain);

return new ZalgoPromise((resolve, reject) => {
return new ZalgoPromise((resolve, reject) => {

iframe.onload = resolve;
iframe.onerror = reject;
iframe.onload = resolve;
iframe.onerror = reject;

}).then(() => {
}).then(() => {

return onWindowReady(bridge, CONFIG.BRIDGE_TIMEOUT, `Bridge ${url}`);
return onWindowReady(bridge, CONFIG.BRIDGE_TIMEOUT, `Bridge ${url}`);

}).then(() => {
}).then(() => {

return bridge;
});
return bridge;
});
});
});
Expand Down Expand Up @@ -215,9 +208,10 @@ export function linkUrl(win : CrossDomainWindowType, url : string) {
export function destroyBridges() {
for (let domain of Object.keys(global.bridgeFrames)) {
let frame = global.bridgeFrames[domain];
if (frame && frame.parentNode) {
if (frame.parentNode) {
frame.parentNode.removeChild(frame);
}
}
global.bridgeFrames = {};
global.bridges = {};
}

0 comments on commit 2f9dbc3

Please # to comment.