Skip to content

Commit

Permalink
Merge branch 'main' into pb/ot
Browse files Browse the repository at this point in the history
  • Loading branch information
Pangoraw committed Oct 4, 2022
2 parents 2a6b1c0 + fa4e5fe commit fee51f7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 22 deletions.
4 changes: 0 additions & 4 deletions src/notebook/Cell.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@ function Base.convert(::Type{Cell}, cell::Dict)
metadata=cell["metadata"],
)
end
function Base.convert(::Type{UUID}, string::String)
UUID(string)
end


"Returns whether or not the cell is **explicitely** disabled."
is_disabled(c::Cell) = get(c.metadata, METADATA_DISABLED_KEY, DEFAULT_CELL_METADATA[METADATA_DISABLED_KEY])
Expand Down
2 changes: 1 addition & 1 deletion src/webserver/Dynamic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ function send_notebook_changes!(πŸ™‹::ClientRequest; commentary::Any=nothing)
if client.connected_notebook !== nothing && client.connected_notebook.notebook_id == πŸ™‹.notebook.notebook_id
current_dict = get(current_state_for_clients, client, :empty)
patches = Firebasey.diff(current_dict, notebook_dict)
patches_as_dicts::Array{Dict} = patches
patches_as_dicts::Array{Dict} = Firebasey._convert(Array{Dict}, patches)
current_state_for_clients[client] = deep_enough_copy(notebook_dict)

# Make sure we do send a confirmation to the client who made the request, even without changes
Expand Down
45 changes: 28 additions & 17 deletions src/webserver/Firebasey.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
### A Pluto.jl notebook ###
# v0.19.9
# v0.19.12

using Markdown
using InteractiveUtils
Expand Down Expand Up @@ -227,11 +227,6 @@ function Base.convert(::Type{Dict}, patch::RemovePatch)
Dict{String,Any}("op" => "remove", "path" => patch.path)
end

# ╔═║ fafcb8b8-cde9-4f99-9bab-8128025953a4
function Base.convert(::Type{<:Dict}, patch::ReplacePatch)
Dict{String,Any}("op" => "replace", "path" => patch.path, "value" => patch.value)
end

# ╔═║ 921a130e-b028-4f91-b077-3bd79dcb6c6d
function Base.convert(::Type{JSONPatch}, patch_dict::Dict)
op = patch_dict["op"]
Expand All @@ -258,12 +253,6 @@ Base.convert(Dict, AddPatch([:x, :y], 10))
Base.convert(Dict, RemovePatch([:x, :y]))
╠═║ =#

# ╔═║ 7feeee3a-3aec-47ce-b8d7-74a0d9b0b381
# ╠═║ skip_as_script = true
#=╠═║
Base.convert(Dict, ReplacePatch([:x, :y], 10))
╠═║ =#

# ╔═║ 6d67f8a5-0e0c-4b6e-a267-96b34d580946
# ╠═║ skip_as_script = true
#=╠═║
Expand Down Expand Up @@ -702,6 +691,28 @@ end
md"### applypatch! AddPatch"
╠═║ =#

# ╔═║ d7ea6052-9d9f-48e3-92fb-250afd69e417
begin
_convert(::Type{Base.UUID}, s::String) = Base.UUID(s)
_convert(::Type{T}, a::AbstractArray) where {T<:Array} = _convert.(eltype(T), a)
_convert(x, y) = convert(x, y)

function _convert(::Type{<:Dict}, patch::ReplacePatch)
Dict{String,Any}("op" => "replace", "path" => patch.path, "value" => patch.value)
end

function _setproperty!(x, f::Symbol, v)
type = fieldtype(typeof(x), f)
return setfield!(x, f, _convert(type, v))
end
end

# ╔═║ 7feeee3a-3aec-47ce-b8d7-74a0d9b0b381
# ╠═║ skip_as_script = true
#=╠═║
_convert(Dict, ReplacePatch([:x, :y], 10))
╠═║ =#

# ╔═║ dd87ca7e-2de1-11eb-2ec3-d5721c32f192
function applypatch!(value, patch::AddPatch)
if length(patch.path) == 0
Expand All @@ -721,7 +732,7 @@ function applypatch!(value, patch::AddPatch)
if strict_applypatch[]
@assert getproperty(subvalue, key) === nothing
end
setproperty!(subvalue, key, patch.value)
_setproperty!(subvalue, key, patch.value)
end
end
return value
Expand Down Expand Up @@ -758,7 +769,7 @@ function applypatch!(value, patch::ReplacePatch)
if strict_applypatch[]
@assert getproperty(subvalue, key) !== nothing
end
setproperty!(subvalue, key, patch.value)
_setproperty!(subvalue, key, patch.value)
end
end
return value
Expand Down Expand Up @@ -795,7 +806,7 @@ function applypatch!(value, patch::RemovePatch)
if strict_applypatch[]
@assert getproperty(subvalue, key) !== nothing
end
setproperty!(subvalue, key, nothing)
_setproperty!(subvalue, key, nothing)
end
end
return value
Expand Down Expand Up @@ -1037,7 +1048,7 @@ end

# ╔═║ 34d86e02-dd34-4691-bb78-3023568a5d16
#=╠═║
@track Base.convert(JSONPatch, convert(Dict, replace_patch)) == replace_patch
@track Base.convert(JSONPatch, _convert(Dict, replace_patch)) == replace_patch
╠═║ =#

# ╔═║ 95ff676d-73c8-44cb-ac35-af94418737e9
Expand Down Expand Up @@ -1147,7 +1158,6 @@ end
# β•Ÿβ”€07eeb122-6706-4544-a007-1c8d6581eec8
# ╠═b48e2c08-a94a-4247-877d-949d92dde626
# β•Ÿβ”€c59b30b9-f702-41f1-bb2e-1736c8cd5ede
# ╠═fafcb8b8-cde9-4f99-9bab-8128025953a4
# β•Ÿβ”€7feeee3a-3aec-47ce-b8d7-74a0d9b0b381
# ╠═921a130e-b028-4f91-b077-3bd79dcb6c6d
# β•Ÿβ”€6d67f8a5-0e0c-4b6e-a267-96b34d580946
Expand Down Expand Up @@ -1220,6 +1230,7 @@ end
# ╠═48a45941-2489-4666-b4e5-88d3f82e5145
# ╠═752b2da3-ff24-4758-8843-186368069888
# β•Ÿβ”€3e285076-1d97-4728-87cf-f71b22569e57
# ╠═d7ea6052-9d9f-48e3-92fb-250afd69e417
# ╠═dd87ca7e-2de1-11eb-2ec3-d5721c32f192
# β•Ÿβ”€c3e4738f-4568-4910-a211-6a46a9d447ee
# β•Ÿβ”€a11e4082-4ff4-4c1b-9c74-c8fa7dcceaa6
Expand Down

0 comments on commit fee51f7

Please sign in to comment.