GenieFramework / Stipple.jl

The reactive UI library for interactive data applications with pure Julia.
MIT License
324 stars 27 forks source link

stipple_parse structs #279

Closed hhaensel closed 6 months ago

hhaensel commented 6 months ago

Add automatic struct parsing for both normal structs and structs defined by @kwdef:

struct HH1
  c::Int
  d::Int
end

struct HH2
  a::Int
  b::HH1
end

hh2 = HH2(1, HH1(2, 3))
hh2_dict = JSON3.read(json(hh2), Dict)

Base.@kwdef struct T1
  c::Int = 1
  d::Int = 3
end

Base.@kwdef struct T2
  a::Int = 1
  b::T1 = T1()
end

Stipple.stipple_parse(HH2, hh2_dict)
# HH2(1, HH1(2, 3))

Stipple.stipple_parse(T1, Dict())
# T1(1, 3)

Stipple.stipple_parse(T2, Dict())
# T2(1, T1(1, 3))