From cfa93c3e8114042f6c435654874608f8bfdb9016 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Helmut=20H=C3=A4nsel?= Date: Sun, 8 Oct 2023 09:19:56 +0200 Subject: [PATCH 1/4] interoperability for Stipple.JSONText and JSON.JSONText for JSON3 and JSON --- Project.toml | 16 ++++++++++------ ext/StippleJSON.jl | 10 ++++++++++ ext/StippleJSONExt.jl | 18 ++++++++++++++++++ src/Stipple.jl | 10 +++++++++- test/runtests.jl | 11 +++++++++++ 5 files changed, 58 insertions(+), 7 deletions(-) create mode 100644 ext/StippleJSON.jl create mode 100644 ext/StippleJSONExt.jl diff --git a/Project.toml b/Project.toml index af8230d7..b0528303 100644 --- a/Project.toml +++ b/Project.toml @@ -21,39 +21,43 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Reexport = "189a3867-3050-52da-a836-e630ba90ab69" Requires = "ae029012-a4dd-5104-9daa-d747884805df" StructTypes = "856f2bd8-1eba-4b0a-8007-ebc267875bd4" -Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" +Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" [weakdeps] DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" +JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" [extensions] StippleDataFramesExt = "DataFrames" StippleOffsetArraysExt = "OffsetArrays" +StippleJSONExt = "JSON" [compat] +DataFrames = "1" FilePathsBase = "0.9" Genie = "5.18" GenieSession = "1" GenieSessionFileSession = "1" JSON3 = "1.9" +JSON = "0.20, 0.21" MacroTools = "0.5" Mixers = "0.1.2" Observables = "0.3, 0.4, 0.5" +OffsetArrays = "1" OrderedCollections = "1" Parameters = "0.12" Reexport = "1" Requires = "1" StructTypes = "1.8" -julia = "1.6" -OffsetArrays = "1" -DataFrames = "1" Tables = "1" +julia = "1.6" [extras] -Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" +JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Test", "DataFrames", "OffsetArrays"] +test = ["Test", "DataFrames", "JSON", "OffsetArrays"] diff --git a/ext/StippleJSON.jl b/ext/StippleJSON.jl new file mode 100644 index 00000000..f12b0202 --- /dev/null +++ b/ext/StippleJSON.jl @@ -0,0 +1,10 @@ +# garantee interoperability of different JSONTText definitions of JSON3 and JSON + +JSON.JSONText(json::Stipple.JSONText) = JSON.JSONText(json.s) +JSON.show_json(io::JSON.Writer.CompactContext, s::JSON.Writer.CS, json::Stipple.JSONText) = write(io, json.s) +JSON.Writer.lower(json::Stipple.JSONText) = JSON.parse(json.s) + +Stipple.JSONText(json::JSON.JSONText) = Stipple.JSONText(json.s) +@inline StructTypes.StructType(::Type{JSON.JSONText}) = JSON3.RawType() +@inline StructTypes.construct(::Type{JSON.JSONText}, json::JSON3.RawValue) = JSONText(string(json)) +@inline JSON3.rawbytes(json::JSON.JSONText) = codeunits(json.s) \ No newline at end of file diff --git a/ext/StippleJSONExt.jl b/ext/StippleJSONExt.jl new file mode 100644 index 00000000..60c953c1 --- /dev/null +++ b/ext/StippleJSONExt.jl @@ -0,0 +1,18 @@ +module StippleJSONExt + +using Stipple +using JSON + +# garantee interoperability of different JSONTText definitions in Stipple and JSON +# for both JSON3 and JSON + +JSON.JSONText(json::Stipple.JSONText) = JSON.JSONText(json.s) +JSON.show_json(io::JSON.Writer.CompactContext, s::JSON.Writer.CS, json::Stipple.JSONText) = write(io, json.s) +JSON.Writer.lower(json::Stipple.JSONText) = JSON.parse(json.s) + +Stipple.JSONText(json::JSON.JSONText) = Stipple.JSONText(json.s) +@inline StructTypes.StructType(::Type{JSON.JSONText}) = JSON3.RawType() +@inline StructTypes.construct(::Type{JSON.JSONText}, json::JSON3.RawValue) = JSONText(string(json)) +@inline JSON3.rawbytes(json::JSON.JSONText) = codeunits(json.s) + +end \ No newline at end of file diff --git a/src/Stipple.jl b/src/Stipple.jl index c899ef94..d2950b9c 100644 --- a/src/Stipple.jl +++ b/src/Stipple.jl @@ -15,6 +15,8 @@ existing Vue.js libraries. """ module Stipple +const PRECOMPILE = Ref(false) + """ @using_except(expr) @@ -216,6 +218,12 @@ function __init__() include(joinpath(@__DIR__, "..", "ext", "StippleDataFrames.jl")) # Core.eval(@__MODULE__, Meta.parse(join(jl, ';')).args[3]) end + + @require JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" begin + # evaluate the code of the extension without the surrounding module + include(joinpath(@__DIR__, "..", "ext", "StippleJSON.jl")) + # Core.eval(@__MODULE__, Meta.parse(join(jl, ';')).args[3]) + end end end @@ -443,7 +451,7 @@ function init(::Type{M}; # add a timer that checks if the model is outdated and if so prepare the model to be garbage collected LAST_ACTIVITY[Symbol(getchannel(model))] = now() - Timer(setup_purge_checker(model), PURGE_CHECK_DELAY[], interval = PURGE_CHECK_DELAY[]) + PRECOMPILE[] || Timer(setup_purge_checker(model), PURGE_CHECK_DELAY[], interval = PURGE_CHECK_DELAY[]) if is_channels_webtransport() Genie.Assets.channels_subscribe(channel) diff --git a/test/runtests.jl b/test/runtests.jl index ec9efefd..73765ea0 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -350,4 +350,15 @@ end @test cell(sm = 9) == "
" @test cell(col = -1, sm = 9) == "
" +end + +@testset "Compatibility of JSONText between JSON3 and JSON" begin + using JSON + using Stipple + jt1 = JSON.JSONText("json text 1") + jt2 = Stipple.JSONText("json text 2") + @test JSON.json(jt1) == "json text 1" + @test Stipple.json(jt1) == "json text 1" + @test JSON.json(jt2) == "json text 2" + @test Stipple.json(jt2) == "json text 2" end \ No newline at end of file From d176fbedd232f2c8601a66cf551ea8915ff4ab01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Helmut=20H=C3=A4nsel?= Date: Sun, 8 Oct 2023 22:13:04 +0200 Subject: [PATCH 2/4] remove extra files for Requires --- Project.toml | 22 +++++++++++----------- ext/StippleDataFrames.jl | 7 ------- ext/StippleDataFramesExt.jl | 7 +++---- ext/StippleJSON.jl | 10 ---------- ext/StippleJSONExt.jl | 3 ++- ext/StippleOffsetArrays.jl | 12 ------------ ext/StippleOffsetArraysExt.jl | 3 ++- ext/StippleTablesExt.jl | 7 ------- src/Stipple.jl | 12 +++--------- 9 files changed, 21 insertions(+), 62 deletions(-) delete mode 100644 ext/StippleDataFrames.jl delete mode 100644 ext/StippleJSON.jl delete mode 100644 ext/StippleOffsetArrays.jl delete mode 100644 ext/StippleTablesExt.jl diff --git a/Project.toml b/Project.toml index b0528303..e243b073 100644 --- a/Project.toml +++ b/Project.toml @@ -23,24 +23,14 @@ Requires = "ae029012-a4dd-5104-9daa-d747884805df" StructTypes = "856f2bd8-1eba-4b0a-8007-ebc267875bd4" Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" -[weakdeps] -DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" -JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" -OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" - -[extensions] -StippleDataFramesExt = "DataFrames" -StippleOffsetArraysExt = "OffsetArrays" -StippleJSONExt = "JSON" - [compat] DataFrames = "1" FilePathsBase = "0.9" Genie = "5.18" GenieSession = "1" GenieSessionFileSession = "1" -JSON3 = "1.9" JSON = "0.20, 0.21" +JSON3 = "1.9" MacroTools = "0.5" Mixers = "0.1.2" Observables = "0.3, 0.4, 0.5" @@ -53,6 +43,11 @@ StructTypes = "1.8" Tables = "1" julia = "1.6" +[extensions] +StippleDataFramesExt = "DataFrames" +StippleJSONExt = "JSON" +StippleOffsetArraysExt = "OffsetArrays" + [extras] DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" @@ -61,3 +56,8 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] test = ["Test", "DataFrames", "JSON", "OffsetArrays"] + +[weakdeps] +DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" +JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" +OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" diff --git a/ext/StippleDataFrames.jl b/ext/StippleDataFrames.jl deleted file mode 100644 index ba61dd74..00000000 --- a/ext/StippleDataFrames.jl +++ /dev/null @@ -1,7 +0,0 @@ -function Stipple.stipple_parse(::Type{DF} where DF <: DataFrames.AbstractDataFrame, d::Vector) - isempty(d) ? DF() : reduce(vcat, DataFrames.DataFrame.(d)) -end - -function Stipple.render(df::DataFrames.DataFrame) - OrderedDict(zip(names(df), eachcol(df))) -end \ No newline at end of file diff --git a/ext/StippleDataFramesExt.jl b/ext/StippleDataFramesExt.jl index 12fd0ddb..4f606740 100644 --- a/ext/StippleDataFramesExt.jl +++ b/ext/StippleDataFramesExt.jl @@ -1,9 +1,8 @@ module StippleDataFramesExt -@static if isdefined(Base, :get_extension) - using Stipple - using DataFrames -end +using Stipple + +isdefined(Base, :get_extension) ? using DataFrames : using ..DataFrames function Stipple.stipple_parse(::Type{DF} where DF <: DataFrames.AbstractDataFrame, d::Vector) isempty(d) ? DF() : reduce(vcat, DataFrames.DataFrame.(d)) diff --git a/ext/StippleJSON.jl b/ext/StippleJSON.jl deleted file mode 100644 index f12b0202..00000000 --- a/ext/StippleJSON.jl +++ /dev/null @@ -1,10 +0,0 @@ -# garantee interoperability of different JSONTText definitions of JSON3 and JSON - -JSON.JSONText(json::Stipple.JSONText) = JSON.JSONText(json.s) -JSON.show_json(io::JSON.Writer.CompactContext, s::JSON.Writer.CS, json::Stipple.JSONText) = write(io, json.s) -JSON.Writer.lower(json::Stipple.JSONText) = JSON.parse(json.s) - -Stipple.JSONText(json::JSON.JSONText) = Stipple.JSONText(json.s) -@inline StructTypes.StructType(::Type{JSON.JSONText}) = JSON3.RawType() -@inline StructTypes.construct(::Type{JSON.JSONText}, json::JSON3.RawValue) = JSONText(string(json)) -@inline JSON3.rawbytes(json::JSON.JSONText) = codeunits(json.s) \ No newline at end of file diff --git a/ext/StippleJSONExt.jl b/ext/StippleJSONExt.jl index 60c953c1..571bd9c5 100644 --- a/ext/StippleJSONExt.jl +++ b/ext/StippleJSONExt.jl @@ -1,7 +1,8 @@ module StippleJSONExt using Stipple -using JSON + +isdefined(Base, :get_extension) ? using JSON : using ..JSON # garantee interoperability of different JSONTText definitions in Stipple and JSON # for both JSON3 and JSON diff --git a/ext/StippleOffsetArrays.jl b/ext/StippleOffsetArrays.jl deleted file mode 100644 index 60fc4bfd..00000000 --- a/ext/StippleOffsetArrays.jl +++ /dev/null @@ -1,12 +0,0 @@ -function Stipple.convertvalue(targetfield::Union{Ref{T}, Reactive{T}}, value) where T <: OffsetArrays.OffsetArray - a = Stipple.stipple_parse(eltype(targetfield), value) - - # if value is not an OffsetArray use the offset of the current array - if ! isa(value, OffsetArrays.OffsetArray) - o = targetfield[].offsets - OffsetArrays.OffsetArray(a, OffsetArrays.Origin(1 .+ o)) - # otherwise use the existing value - else - a - end -end \ No newline at end of file diff --git a/ext/StippleOffsetArraysExt.jl b/ext/StippleOffsetArraysExt.jl index 0070e3d1..9af9f865 100644 --- a/ext/StippleOffsetArraysExt.jl +++ b/ext/StippleOffsetArraysExt.jl @@ -1,7 +1,8 @@ module StippleOffsetArraysExt using Stipple -using OffsetArrays + +isdefined(Base, :get_extension) ? using OffsetArrays : using ..OffsetArrays function Stipple.convertvalue(targetfield::Union{Ref{T}, Reactive{T}}, value) where T <: OffsetArrays.OffsetArray a = Stipple.stipple_parse(eltype(targetfield), value) diff --git a/ext/StippleTablesExt.jl b/ext/StippleTablesExt.jl deleted file mode 100644 index 097f8624..00000000 --- a/ext/StippleTablesExt.jl +++ /dev/null @@ -1,7 +0,0 @@ -module StippleTablesExt - -using Stipple -import Tables - - -end \ No newline at end of file diff --git a/src/Stipple.jl b/src/Stipple.jl index d2950b9c..4869f152 100644 --- a/src/Stipple.jl +++ b/src/Stipple.jl @@ -208,21 +208,15 @@ function __init__() @static if !isdefined(Base, :get_extension) @require OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" begin - # evaluate the code of the extension without the surrounding module - include(joinpath(@__DIR__, "..", "ext", "StippleOffsetArrays.jl")) - # Core.eval(@__MODULE__, Meta.parse(join(jl, ';')).args[3]) + include(joinpath(@__DIR__, "..", "ext", "StippleOffsetArraysExt.jl")) end @require DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" begin - # evaluate the code of the extension without the surrounding module - include(joinpath(@__DIR__, "..", "ext", "StippleDataFrames.jl")) - # Core.eval(@__MODULE__, Meta.parse(join(jl, ';')).args[3]) + include(joinpath(@__DIR__, "..", "ext", "StippleDataFramesExt.jl")) end @require JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" begin - # evaluate the code of the extension without the surrounding module - include(joinpath(@__DIR__, "..", "ext", "StippleJSON.jl")) - # Core.eval(@__MODULE__, Meta.parse(join(jl, ';')).args[3]) + include(joinpath(@__DIR__, "..", "ext", "StippleJSONExt.jl")) end end end From 1dbb1a83277dd0e4afc8c5e17a6180199a445700 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Helmut=20H=C3=A4nsel?= Date: Fri, 13 Oct 2023 12:27:54 +0200 Subject: [PATCH 3/4] no parsing of jsontext in lower() --- ext/StippleJSON.jl | 2 +- ext/StippleJSONExt.jl | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ext/StippleJSON.jl b/ext/StippleJSON.jl index f12b0202..33d74c1e 100644 --- a/ext/StippleJSON.jl +++ b/ext/StippleJSON.jl @@ -2,7 +2,7 @@ JSON.JSONText(json::Stipple.JSONText) = JSON.JSONText(json.s) JSON.show_json(io::JSON.Writer.CompactContext, s::JSON.Writer.CS, json::Stipple.JSONText) = write(io, json.s) -JSON.Writer.lower(json::Stipple.JSONText) = JSON.parse(json.s) +JSON.Writer.lower(json::Stipple.JSONText) = json.s Stipple.JSONText(json::JSON.JSONText) = Stipple.JSONText(json.s) @inline StructTypes.StructType(::Type{JSON.JSONText}) = JSON3.RawType() diff --git a/ext/StippleJSONExt.jl b/ext/StippleJSONExt.jl index 60c953c1..6b35ec86 100644 --- a/ext/StippleJSONExt.jl +++ b/ext/StippleJSONExt.jl @@ -5,10 +5,12 @@ using JSON # garantee interoperability of different JSONTText definitions in Stipple and JSON # for both JSON3 and JSON +# Note that `lower` for Stipple.JSONText is not defined as parse(json.s), because that would require +# pure proper JSON. For transmissions of bindings, though, we need to allow to pass object names. JSON.JSONText(json::Stipple.JSONText) = JSON.JSONText(json.s) JSON.show_json(io::JSON.Writer.CompactContext, s::JSON.Writer.CS, json::Stipple.JSONText) = write(io, json.s) -JSON.Writer.lower(json::Stipple.JSONText) = JSON.parse(json.s) +JSON.Writer.lower(json::Stipple.JSONText) = json.s Stipple.JSONText(json::JSON.JSONText) = Stipple.JSONText(json.s) @inline StructTypes.StructType(::Type{JSON.JSONText}) = JSON3.RawType() From aa1a03c64c7b23e106b6b00b220b738a53dea82a Mon Sep 17 00:00:00 2001 From: hhaensel Date: Tue, 17 Oct 2023 10:20:54 +0200 Subject: [PATCH 4/4] fix StructTypes.construct(::Type{JSON.JSONText} --- ext/StippleJSONExt.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/StippleJSONExt.jl b/ext/StippleJSONExt.jl index d15bd159..dafc2d37 100644 --- a/ext/StippleJSONExt.jl +++ b/ext/StippleJSONExt.jl @@ -10,12 +10,12 @@ isdefined(Base, :get_extension) ? using JSON : using ..JSON # pure proper JSON. For transmissions of bindings, though, we need to allow to pass object names. JSON.JSONText(json::Stipple.JSONText) = JSON.JSONText(json.s) -JSON.show_json(io::JSON.Writer.CompactContext, s::JSON.Writer.CS, json::Stipple.JSONText) = write(io, json.s) +JSON.show_json(io::JSON.Writer.CompactContext, ::JSON.Writer.CS, json::Stipple.JSONText) = write(io, json.s) JSON.Writer.lower(json::Stipple.JSONText) = json.s Stipple.JSONText(json::JSON.JSONText) = Stipple.JSONText(json.s) @inline StructTypes.StructType(::Type{JSON.JSONText}) = JSON3.RawType() -@inline StructTypes.construct(::Type{JSON.JSONText}, json::JSON3.RawValue) = JSONText(string(json)) +@inline StructTypes.construct(::Type{JSON.JSONText}, json::JSON3.RawValue) = JSON.JSONText(string(json)) @inline JSON3.rawbytes(json::JSON.JSONText) = codeunits(json.s) end \ No newline at end of file