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

[WIP] Attempting to fix nested signals #191

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions assets/escherd.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@
}
}
Escher.applyPatch = function (id, patch) {
console.log("Escher.applyPatch");
console.dir(Escher.subtrees);
console.log(id);
console.dir(patch);

if (typeof(Escher.patches[id]) === "undefined") {
Escher.patches[id] = []
}
Expand Down
51 changes: 46 additions & 5 deletions src/cli/serve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,41 +110,81 @@ query_dict(qstr) = begin
dict
end

start_updates(sig, window, sock, id=Escher.makeid(sig)) = begin
last_vals = Dict()
last_ids = Dict()

start_updates(sig, window, sock, id=Escher.makeid(sig), depth = 1) = begin
global last_vals
global last_ids

println("START_UPDATES")
println(id)

state = Dict()
state["embedded_signals"] = Dict()
# last_val = render(Escher.empty, state)
init = render(value(sig), state)

write(sock, patch_cmd(id, Patchwork.diff(render(Escher.empty, state), init)))
if (depth in keys(last_vals))
# last_val = render(Escher.empty, state)
last_val = last_vals[depth]
# last_id = last_ids[depth]
else
last_val = render(Escher.empty, state)
# last_id = id
end

foldp(init, filterwhen(window.alive, empty, sig); typ=Any) do prev, next
diff = Patchwork.diff(last_val, init)
last_vals[depth] = init

println("DIFF --------------------")
println(diff)
# if (11 in keys(diff))
# diff = Dict(13 => diff[11])
# end
write(sock, patch_cmd(id, diff))
# last_ids[depth] = id

foldp(init, filterwhen(window.alive, empty, sig); typ=Any) do prev, next
st = Dict()
st["embedded_signals"] = Dict()
rendered_next = render(next, st)

diff = Patchwork.diff(prev, rendered_next)
println("PREV --------------------")
println(prev)
println("RENDERED_NEXT --------------------")
println(rendered_next)
println("DIFF --------------------")
println(diff)

try
write(sock, patch_cmd(id, Patchwork.diff(prev, rendered_next)))
catch ex
if isopen(sock)
rethrow(ex)
end
end
d = depth
for (key, embedded) in st["embedded_signals"]
start_updates(embedded, window, sock, key)
start_updates(embedded, window, sock, key, d + 1)
d += 1
end

rendered_next
end |> preserve

d = depth
for (key, embedded) in state["embedded_signals"]
start_updates(embedded, window, sock, key)
start_updates(embedded, window, sock, key, d + 1)
d += 1
end
end


uisocket(dir) = (req) -> begin
println("uisocket")

file = joinpath(abspath(dir), (req[:params][:file]))

d = query_dict(req[:query])
Expand All @@ -159,6 +199,7 @@ uisocket(dir) = (req) -> begin
# window dimensions and what not

window = Window(dimension=(w*px, h*px))
# start_updates(flatten(tilestream, typ=Any), window, sock, "root")

Reactive.foreach(asset -> write(sock, JSON.json(import_cmd(asset))),
window.assets)
Expand Down