Skip to content

Commit 0638a0f

Browse files
committed
Use initial_value from AbstractPlutoDingetjes.jl
1 parent 01c367a commit 0638a0f

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/runner/PlutoRunner.jl

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ const table_column_display_limit_increase = 30
581581
const tree_display_extra_items = Dict{UUID,Dict{ObjectDimPair,Int64}}()
582582

583583
function formatted_result_of(cell_id::UUID, ends_with_semicolon::Bool, showmore::Union{ObjectDimPair,Nothing}=nothing, workspace::Module=Main)::NamedTuple{(:output_formatted, :errored, :interrupted, :process_exited, :runtime, :published_objects),Tuple{PlutoRunner.MimedOutput,Bool,Bool,Bool,Union{UInt64,Nothing},Dict{String,Any}}}
584-
load_integration_if_needed.(integrations)
584+
load_integrations_if_needed()
585585
currently_running_cell_id[] = cell_id
586586

587587
extra_items = if showmore === nothing
@@ -1117,6 +1117,14 @@ end
11171117
# We have a super cool viewer for objects that are a Tables.jl table. To avoid version conflicts, we only load this code after the user (indirectly) loaded the package Tables.jl.
11181118
# This is similar to how Requires.jl works, except we don't use a callback, we just check every time.
11191119
const integrations = Integration[
1120+
Integration(
1121+
id = Base.PkgId(UUID(reinterpret(Int128, codeunits("Paul Berg Berlin")) |> first), "AbstractPlutoDingetjes"),
1122+
code = quote
1123+
if v"1.0.0" <= AbstractPlutoDingetjes.MY_VERSION < v"2.0.0"
1124+
initial_value_getter_ref[] = AbstractPlutoDingetjes.Bonds.initial_value
1125+
end
1126+
end,
1127+
)
11201128
Integration(
11211129
id = Base.PkgId(UUID("0c5d862f-8b57-4792-8d23-62f2024744c7"), "Symbolics"),
11221130
code = quote
@@ -1225,6 +1233,8 @@ function load_integration_if_needed(integration::Integration)
12251233
end
12261234
end
12271235

1236+
load_integrations_if_needed() = load_integration_if_needed.(integrations)
1237+
12281238
function load_integration(integration::Integration)
12291239
integration.loaded[] = true
12301240
try
@@ -1432,6 +1442,8 @@ function show(io::IO, ::MIME"text/html", bond::Bond)
14321442
end
14331443
end
14341444

1445+
const initial_value_getter_ref = useRef{Function}(bond -> missing)
1446+
14351447
"""
14361448
`@bind symbol element`
14371449
@@ -1450,11 +1462,12 @@ x^2
14501462
The first cell will show a slider as the cell's output, ranging from 0 until 100.
14511463
The second cell will show the square of `x`, and is updated in real-time as the slider is moved.
14521464
"""
1453-
macro bind(def, element)
1465+
macro bind(def, element)
14541466
if def isa Symbol
14551467
quote
1468+
$(load_integrations_if_needed)()
14561469
local el = $(esc(element))
1457-
global $(esc(def)) = Core.applicable(Base.get, el) ? Base.get(el) : missing
1470+
global $(esc(def)) = Core.applicable(Base.get, el) ? Base.get(el) : $(initial_value_getter_ref)[](el)
14581471
PlutoRunner.Bond(el, $(Meta.quot(def)))
14591472
end
14601473
else
@@ -1467,8 +1480,9 @@ Will be inserted in saved notebooks that use the @bind macro, make sure that the
14671480
"""
14681481
const fake_bind = """macro bind(def, element)
14691482
quote
1483+
local iv = try Base.loaded_modules[Base.PkgId(Base.UUID("6e696c72-6542-2067-7265-42206c756150"), "AbstractPlutoDingetjes")].Bonds.initial_value catch; b -> missing; end
14701484
local el = \$(esc(element))
1471-
global \$(esc(def)) = Core.applicable(Base.get, el) ? Base.get(el) : missing
1485+
global \$(esc(def)) = Core.applicable(Base.get, el) ? Base.get(el) : iv(el)
14721486
el
14731487
end
14741488
end"""

0 commit comments

Comments
 (0)