Skip to content

Commit

Permalink
πŸ› Fix #87
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsp committed Apr 16, 2020
1 parent 047d264 commit 41ee210
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = "Pluto"
uuid = "c3e4b0f8-55cb-11ea-2926-15256bba5781"
license = "MIT"
authors = ["Fons van der Plas <[email protected]>", "MikoΕ‚aj Bochenski <[email protected]>"]
version = "0.7.3"
version = "0.7.4"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Expand Down
7 changes: 4 additions & 3 deletions assets/bond.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
observablehq.Library()

function makeBond(bondNode) {
if(bondNode.getRootNode() != document){
return
}
bondNode.generator.next().value.then(val => {
console.log("New val: "+val)
window.refreshAllCompletionPromise()
window.client.sendreceive("bond_set", {
sym: bondNode.getAttribute("def"),
val: val,
}).then(u => {
// TODO: wait for all cells to finish running, maybe make this an event
})
window.allCellsCompletedPromise.then(_ => {
makeBond(bondNode)
Expand All @@ -25,7 +26,7 @@ document.addEventListener("celloutputchanged", (e) => {
const bondNodes = cellNode.querySelectorAll("bond")

bondNodes.forEach(bondNode => {
bondNode.generator = observablehq.Generators.input(bondNode.firstChild)
bondNode.generator = observablehq.Generators.input(bondNode.firstElementChild)
window.allCellsCompletedPromise.then(_ => {
makeBond(bondNode)
})
Expand Down
11 changes: 4 additions & 7 deletions assets/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,10 @@ class PlutoConnection {
})
}, 1000)
}

psocket = null

getUniqueShortID() {
return crypto.getRandomValues(new Uint32Array(1))[0].toString(36)
}
clientID = this.getUniqueShortID()

sentRequests = {}

MSG_DELIM = "IUUQ.km jt ejggjdvmu vhi"

send(messageType, body, cellUUID = undefined, createPromise=false) {
const requestID = this.getUniqueShortID()
Expand Down Expand Up @@ -187,6 +180,10 @@ class PlutoConnection {
this.onDisconnect = onDisconnect

this.currentlyConnected = false
this.psocket = null
this.MSG_DELIM = "IUUQ.km jt ejggjdvmu vhi"
this.clientID = this.getUniqueShortID()
this.sentRequests = {}

window.addEventListener("unload", e => {
this.send("disconnect", {})
Expand Down
2 changes: 1 addition & 1 deletion assets/editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@

code {
font-family: monospace;
font-size: .75rem;
font-size: .75em;
}

cell.error>code {
Expand Down
7 changes: 6 additions & 1 deletion assets/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,12 @@ document.addEventListener("DOMContentLoaded", () => {
document.head.appendChild(tag)
}
} else {
eval(scripts[i].innerHTML)
var result = Function(scripts[i].innerHTML).bind(outputNode)()
if(!scripts[i].previousElementSibling && !scripts[i].nextElementSibling){
if(result && result.nodeType === Node.ELEMENT_NODE){
scripts[i].parentElement.insertBefore(result, scripts[i])
}
}
}
}
} catch (err) {
Expand Down
14 changes: 8 additions & 6 deletions src/webserver/Dynamic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,14 @@ responses[:bond_set] = (body, notebook::Notebook; initiator::Union{Initiator, Mi
new_val = body["val"]
putnotebookupdates!(notebook, UpdateMessage(:bond_update, body, notebook, nothing, initiator))

function custom_deletion_hook(notebook::Notebook, to_delete_vars::Set{Symbol}, to_reimport::Set{Expr}; to_run::Array{Cell, 1})
push!(to_delete_vars, bound_sym) # also delete the bound symbol
WorkspaceManager.delete_vars(notebook, to_delete_vars, to_reimport)
WorkspaceManager.eval_in_workspace(notebook, :($bound_sym = $new_val))
if !isempty(where_assigned(notebook, Set{Symbol}([bound_sym])))
function custom_deletion_hook(notebook::Notebook, to_delete_vars::Set{Symbol}, to_reimport::Set{Expr}; to_run::Array{Cell, 1})
push!(to_delete_vars, bound_sym) # also delete the bound symbol
WorkspaceManager.delete_vars(notebook, to_delete_vars, to_reimport)
WorkspaceManager.eval_in_workspace(notebook, :($bound_sym = $new_val))
end
to_reeval = where_referenced(notebook, Set{Symbol}([bound_sym]))
run_reactive_async!(notebook, to_reeval; deletion_hook=custom_deletion_hook)
end

to_reeval = where_referenced(notebook, Set{Symbol}([bound_sym]))
run_reactive_async!(notebook, to_reeval; deletion_hook=custom_deletion_hook)
end
11 changes: 6 additions & 5 deletions src/webserver/WebServer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,14 @@ function flushclient(client::Client)
write(client.stream, serialize_message(next_to_send))
else
@info "Client $(client.id) stream closed."
put!(flushtoken, token)
return false
end
end
catch ex
bt = stacktrace(catch_backtrace())
@warn "Failed to write to WebSocket of $(client.id) " exception=(ex,bt)
put!(flushtoken, token)
return false
end
put!(flushtoken, token)
Expand Down Expand Up @@ -109,7 +111,6 @@ end
responses = Dict{Symbol,Function}()

const MSG_DELIM = "IUUQ.km jt ejggjdvmu vhi" # riddle me this, Julius
const MSG_DELIM_BYTES = codeunits(MSG_DELIM) |> Vector{UInt8}

"""Start a Pluto server _synchronously_ (i.e. blocking call) on `http://localhost:[port]/`.
Expand All @@ -131,11 +132,11 @@ function run(port = 1234, launchbrowser = false)
try
parentbody = let
# For some reason, long (>256*512 bytes) WS messages get split up - `readavailable` only gives the first 256*512
data = UInt8[]
while !endswith(data, MSG_DELIM_BYTES)
push!(data, readavailable(clientstream)...)
data = ""
while !endswith(data, MSG_DELIM)
data = data * String(readavailable(clientstream))
end
JSON.parse(String(view(data, 1:(lastindex(data)-length(MSG_DELIM_BYTES)))))
JSON.parse(SubString(data, 1:(lastindex(data)-length(MSG_DELIM))))
end
process_ws_message(parentbody, clientstream)
catch ex
Expand Down

2 comments on commit 41ee210

@fonsp
Copy link
Owner Author

@fonsp fonsp commented on 41ee210 Apr 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/13128

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.7.4 -m "<description of version>" 41ee210c8e0d29225185ad05aa6227ef01923cda
git push origin v0.7.4

Please sign in to comment.