From 46907f446b6c3a61b408adb3a463cd71f8f02ece Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 16 Feb 2016 11:42:01 -0800 Subject: [PATCH] Listening for page loaded event instead of set timeout === less lag --- examples/edit.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/examples/edit.js b/examples/edit.js index f9a7c41623..c0037d1212 100644 --- a/examples/edit.js +++ b/examples/edit.js @@ -1895,16 +1895,18 @@ entityListTool.webView.eventBridge.webEventReceived.connect(function(data) { // Now we want to activate the partice explorer panel! particleExplorerTool.createWebView(); var properties = Entities.getEntityProperties(ids[0]); - var data = { + var particleData = { messageType: "particle_settings", currentProperties: properties }; particleExplorerTool.setActiveParticleEntity(ids[0]); - Script.setTimeout(function() { - // Wait for event bridge on web side to open - particleExplorerTool.webView.eventBridge.emitScriptEvent(JSON.stringify(data)); - }, 2000) + particleExplorerTool.webView.eventBridge.webEventReceived.connect(function(data) { + var data = JSON.parse(data); + if (data.messageType === "page_loaded") { + particleExplorerTool.webView.eventBridge.emitScriptEvent(JSON.stringify(particleData)); + } + }); } else { particleExplorerTool.destroyWebView(); }