From 039f74dbd4df982444396ea873b99b9b960d62bb Mon Sep 17 00:00:00 2001 From: hhaensel Date: Wed, 8 Nov 2023 13:44:38 +0100 Subject: [PATCH] support indexing with `end` --- src/stipple/reactivity.jl | 3 +++ test/runtests.jl | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/stipple/reactivity.jl b/src/stipple/reactivity.jl index 52274fb4..b4ce33be 100644 --- a/src/stipple/reactivity.jl +++ b/src/stipple/reactivity.jl @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index 57fb4221..808ebf93 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -378,4 +378,20 @@ end @test Stipple.json(jt1) == "json text 1" @test JSON.json(jt2) == "json text 2" @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 \ No newline at end of file