Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patching script tags #14

Open
JobJob opened this issue Feb 5, 2016 · 1 comment
Open

Patching script tags #14

JobJob opened this issue Feb 5, 2016 · 1 comment

Comments

@JobJob
Copy link

JobJob commented Feb 5, 2016

I'm doing some crude interfacing with some js code (in IJulia for now). I've had cause to do something like this:

using Patchwork, Interact
@manipulate for curval in 0:0.1:10
    Elem(:div, [
        #other stuff...,
        Elem(:script, "var best_global_evarrr = $curval"),
        Elem(:script, "//ongoing process that uses best_global_evarrr")
    ])
end

When you move the slider, the text (code) of the first <script> gets patched, but the code doesn't get run. Seems that the whole <script> element actually needs to be removed and re-added, rather than just the text being modified in order for the browser to run it.

This change to diff.jl makes it work (only tested in chrome), but I don't know if it's the right solution.

@@ -98,7 +98,16 @@ function diff!{ns, tag}(a::Elem{ns, tag}, b::Elem{ns, tag}, index, patches)
         patch = push!(patch, DictDiff(proppatch))
     end

-    diff!(a.children, b.children, index, patches, parentpatch=patch)
+    if tag == :script
+        scriptpatch = Dict()
+        diff!(a.children, b.children, 0, scriptpatch)
+        if !isempty(scriptpatch)
+            return patches[index] = Overwrite(b)
+        end
+    else
+        diff!(a.children, b.children, index, patches, parentpatch=patch)
+    end
+
     if !isempty(patch)
         patches[index] = patch
     end
@shashi
Copy link
Owner

shashi commented Apr 13, 2016

Interesting, it's probably better to use HTML("<script>...</script>") here instead of Patchwork.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants