Skip to content

Commit

Permalink
Use IIFE for injected javascript. (#63)
Browse files Browse the repository at this point in the history
Otherwise the global `name` variable is overriden by the last assigned
callback and all function invocations target the last defined callback.
  • Loading branch information
muji authored Feb 23, 2021
1 parent b0ba7c2 commit b963030
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/webview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ impl WebViewBuilder {
F: FnMut(&Dispatcher, i32, Vec<Value>) -> Result<()> + Send + 'static,
{
let js = format!(
r#"var name = {:?};
r#"(function() {{
var name = {:?};
var RPC = window._rpc = (window._rpc || {{nextSeq: 1}});
window[name] = function() {{
var seq = RPC.nextSeq++;
Expand All @@ -110,6 +111,7 @@ impl WebViewBuilder {
}}));
return promise;
}}
}})()
"#,
name
);
Expand Down

0 comments on commit b963030

Please sign in to comment.