Skip to content

Commit

Permalink
Merge pull request #238 from GenieFramework/hh-indexing
Browse files Browse the repository at this point in the history
support indexing with `end`
  • Loading branch information
hhaensel authored Nov 10, 2023
2 parents b1c359c + 82a4a09 commit 837039a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/stipple/reactivity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ end
import Base.map!
@inline Base.map!(f::F, r::Reactive, os...; update::Bool=true) where F = Base.map!(f::F, getfield(r, :o), os...; update=update)

Base.axes(r::Reactive, args...) = Base.axes(getfield(getfield(r, :o), :val), args...)
Base.lastindex(r::Reactive, args...) = Base.lastindex(getfield(getfield(r, :o), :val), args...)

const R = Reactive
const PUBLIC = 1
const PRIVATE = 2
Expand Down
18 changes: 17 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,22 @@ end
@test Stipple.json(jt2) == "json text 2"
end

@testset "Indexing with `end`" begin
r = R([1, 2, 3])
on(r) do r
r[end - 1] += 1
end
@test r[end] == 3
r[end] = 4
@test r[end - 1] == 3
@test r[end] == 4

df = DataFrame(:a => 1:3, :b => 12:14)
@test df[end, 1] == 3
@test df[end, end] == 14
@test df[:, end] == 12:14
end

@testset "adding and removing stylesheets" begin
function my_css()
[style("""
Expand All @@ -399,4 +415,4 @@ end
@test Stipple.Layout.THEMES[end] == my_css
remove_css(my_css, byname = true)
@test findfirst(==(my_css), Stipple.Layout.THEMES) === nothing
end
end

0 comments on commit 837039a

Please sign in to comment.