Skip to content

Commit

Permalink
Changes for new Reactive
Browse files Browse the repository at this point in the history
  • Loading branch information
shashi committed Nov 17, 2015
1 parent b3a381d commit 17f8864
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/IJulia/setup.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function init_comm(x::Signal)
get_data_dict(value, mimes)))
end
end
lift(notify, x)
preserve(map(notify, x))
else
comm = comms[x]
end
Expand Down Expand Up @@ -226,7 +226,7 @@ end
function create_widget_signal(s)
create_view(s.value)
local target = s.value
lift(x->update_view(target, src=x), s, init=nothing)
preserve(map(x->update_view(target, src=x), s, init=nothing))
end

include("statedict.jl")
Expand Down
4 changes: 2 additions & 2 deletions src/Interact.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ module Interact
using Reactive, Compat

import Base: mimewritable, writemime
import Reactive.signal
export signal, Widget, InputWidget

# A widget
abstract Widget <: SignalSource
abstract Widget

# A widget that gives out a signal of type T
abstract InputWidget{T} <: Widget

signal(w::InputWidget) = w.signal
signal(x::Signal) = x

function statedict(w::Widget)
msg = Dict()
Expand Down
6 changes: 3 additions & 3 deletions src/manipulate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ function display_widgets(widgetvars)
map(v -> Expr(:call, esc(:display), esc(v)), widgetvars)
end

function lift_block(block, symbols)
function map_block(block, symbols)
lambda = Expr(:(->), Expr(:tuple, symbols...),
block)
Expr(:call, Reactive.lift, lambda, symbols...)
Expr(:call, map, lambda, map(x -> Expr(:call, signal, x), symbols)...)
end

function symbols(bindings)
Expand All @@ -37,6 +37,6 @@ macro manipulate(expr)
syms = symbols(bindings)
Expr(:let, Expr(:block,
display_widgets(syms)...,
esc(lift_block(block, syms))),
esc(map_block(block, syms))),
map(make_widget, bindings)...)
end
28 changes: 14 additions & 14 deletions src/widgets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const Empty = VERSION < v"0.4.0-dev" ? Nothing : Void
########################## Slider ############################

type Slider{T<:Number} <: InputWidget{T}
signal::Input{T}
signal::Signal{T}
label::AbstractString
value::T
range::Range{T}
Expand All @@ -24,35 +24,35 @@ medianelement(r::Range) = r[(1+length(r))>>1]
slider(args...) = Slider(args...)
slider{T}(range::Range{T};
value=medianelement(range),
signal::Signal{T}=Input(value),
signal::Signal{T}=Signal(value),
label="") =
Slider(signal, label, value, range)

######################### Checkbox ###########################

type Checkbox <: InputWidget{Bool}
signal::Input{Bool}
signal::Signal{Bool}
label::AbstractString
value::Bool
end

checkbox(args...) = Checkbox(args...)
checkbox(value::Bool; signal=Input(value), label="") =
checkbox(value::Bool; signal=Signal(value), label="") =
Checkbox(signal, label, value)
checkbox(; label="", value=false, signal=Input(value)) =
checkbox(; label="", value=false, signal=Signal(value)) =
Checkbox(signal, label, value)

###################### ToggleButton ########################

type ToggleButton <: InputWidget{Bool}
signal::Input{Bool}
signal::Signal{Bool}
label::AbstractString
value::Bool
end

togglebutton(args...) = ToggleButton(args...)

togglebutton(; label="", value=false, signal=Input(value)) =
togglebutton(; label="", value=false, signal=Signal(value)) =
ToggleButton(signal, label, value)

togglebutton(label; kwargs...) =
Expand All @@ -61,12 +61,12 @@ togglebutton(label; kwargs...) =
######################### Button ###########################

type Button{T} <: InputWidget{T}
signal::Input{T}
signal::Signal{T}
label::AbstractString
value::T
end

button(; value=nothing, label="", signal=Input(value)) =
button(; value=nothing, label="", signal=Signal(value)) =
Button(signal, label, value)

button(label; kwargs...) =
Expand All @@ -75,7 +75,7 @@ button(label; kwargs...) =
######################## Textbox ###########################

type Textbox{T} <: InputWidget{T}
signal::Input{T}
signal::Signal{T}
label::AbstractString
@compat range::Union{Empty, Range}
value::T
Expand All @@ -92,7 +92,7 @@ function Textbox(; label="",
# Allow unicode characters even if initiated with ASCII
typ=typeof(value),
range=nothing,
signal=Input{typ}(value))
signal=Signal(typ, value))
if isa(value, AbstractString) && range != nothing
throw(ArgumentError(
"You cannot set a range on a string textbox"
Expand Down Expand Up @@ -121,7 +121,7 @@ end
######################### Textarea ###########################

type Textarea{AbstractString} <: InputWidget{AbstractString}
signal::Input{AbstractString}
signal::Signal{AbstractString}
label::AbstractString
value::AbstractString
end
Expand All @@ -130,7 +130,7 @@ textarea(args...) = Textarea(args...)

textarea(; label="",
value="",
signal=Input(value)) =
signal=Signal(value)) =
Textarea(signal, label, value)

textarea(val; kwargs...) =
Expand Down Expand Up @@ -171,7 +171,7 @@ Options(view::Symbol, options::OptionDict;
icons=[],
tooltips=[],
typ=typeof(value),
signal=Input(value)) =
signal=Signal(value)) =
Options{view, typ}(signal, label, value, value_label, options, icons, tooltips)

addoption(opts, v::NTuple{2}) = opts[string(v[1])] = v[2]
Expand Down

0 comments on commit 17f8864

Please sign in to comment.