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

collect reinterpreted arrays #32

Merged
merged 4 commits into from
Sep 25, 2023
Merged
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
3 changes: 3 additions & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[deps]
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
PlutoExtras = "ed5d0301-4775-4676-b788-cf71e66ff8ed"

[compat]
Documenter = "0.27"
20 changes: 19 additions & 1 deletion src/structbond/main_definitions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,26 @@ function Bonds.initial_value(t::StructBond{T}) where T
transformed = Bonds.initial_value(t.widget)
typeconstructor(T)(transformed)
end

# We have to parse the received array and collect reinterpretarrays as they are
# likely the cause of the weird error in Issue #31
collect_reinterpret!(@nospecialize(x)) = x
function collect_reinterpret!(x::AbstractArray)
for i in eachindex(x)
el = x[i]
if el isa Base.ReinterpretArray
x[i] = collect(el)
elseif el isa AbstractArray
# We do recursive processing
collect_reinterpret!(el)
end
end
return x
end

function Bonds.transform_value(t::StructBond{T}, from_js) where T
transformed = Bonds.transform_value(t.widget, from_js)
# We remove reinterpreted_arrays (See Issue #31)
transformed = Bonds.transform_value(t.widget, collect_reinterpret!(from_js))
typeconstructor(T)(transformed)
end

Expand Down
16 changes: 15 additions & 1 deletion test/structbond.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ load_notebook, Configuration, set_bond_values_reactive
using PlutoExtras
using Markdown
using PlutoExtras.StructBondModule
using PlutoExtras.StructBondModule: structbondtype, popoutwrap, fieldbond, NotDefined, typeasfield
using PlutoExtras.StructBondModule: structbondtype, popoutwrap, fieldbond, NotDefined, typeasfield, collect_reinterpret!
import PlutoExtras.AbstractPlutoDingetjes.Bonds
using Test

Expand Down Expand Up @@ -66,6 +66,20 @@ function noerror(cell; verbose=true)
!cell.errored
end

@testset "collect_reinterpret!" begin
@test collect_reinterpret!(3) === 3
re = collect(reinterpret(UInt8, [.5])) |> x -> reinterpret(Float64, x)
arr = [
0.2,
[1.0],
re,
]
@test collect_reinterpret!(arr) == [
0.2,
[1.0],
[0.5],
]
end

options = Configuration.from_flat_kwargs(; disable_writing_notebook_files=true)
srcdir = normpath(@__DIR__, "./notebooks")
Expand Down
Loading