Skip to content

Commit

Permalink
@out fields restore from session
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian Salceanu committed Aug 6, 2024
1 parent fc126c2 commit d82113d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Stipple"
uuid = "4acbeb90-81a0-11ea-1966-bdaff8155998"
authors = ["Adrian <[email protected]>"]
version = "0.28.12"
version = "0.28.13"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down
14 changes: 9 additions & 5 deletions src/ModelStorage.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ function init_from_storage( t::Type{M};

for f in fieldnames(CM)
field = getfield(model, f)

if field isa Reactive
# restore fields only if a stored model exists, if the field is not part of the internal fields and is not write protected
(
isnothing(stored_model) || f [Stipple.CHANNELFIELDNAME, Stipple.AUTOFIELDS...] || Stipple.isreadonly(f, model) || Stipple.isprivate(f, model) ||
! hasproperty(stored_model, f) || ! hasproperty(model, f) || (field[!] = getfield(stored_model, f)[])
)
if isnothing(stored_model) || f [Stipple.CHANNELFIELDNAME, Stipple.AUTOFIELDS...] ||
Stipple.isprivate(f, model) || ! hasproperty(stored_model, f) || ! hasproperty(model, f)
else
# restore field value from stored model
(field[!] = getfield(stored_model, f)[])
end

# register reactive handlers to automatically save model on session when model changes
if f [Stipple.AUTOFIELDS...]
Expand All @@ -42,7 +45,8 @@ function init_from_storage( t::Type{M};
end
end
else
isnothing(stored_model) || Stipple.isprivate(f, model) || Stipple.isreadonly(f, model) || ! hasproperty(stored_model, f) || ! hasproperty(model, f) || setfield!(model, f, getfield(stored_model, f))
isnothing(stored_model) || Stipple.isprivate(f, model) || Stipple.isreadonly(f, model) ||
! hasproperty(stored_model, f) || ! hasproperty(model, f) || setfield!(model, f, getfield(stored_model, f))
end
end

Expand Down
3 changes: 2 additions & 1 deletion src/ReactiveTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ const TYPES = LittleDict{Module,Union{<:DataType,Nothing}}()
const HANDLERS_FUNCTIONS = LittleDict{Type{<:ReactiveModel},Function}()

function DEFAULT_LAYOUT(; title::String = "Genie App",
meta::D = Dict(), head_content::Union{AbstractString, Vector} = "") where {D <:AbstractDict}
meta::D = Dict(),
head_content::Union{AbstractString, Vector} = "") where {D <:AbstractDict}
tags = Genie.Renderers.Html.for_each(x -> """<meta name="$(string(x.first))" content="$(string(x.second))">\n""", meta)
"""
<!DOCTYPE html>
Expand Down

2 comments on commit d82113d

@essenciary
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/112492

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.28.13 -m "<description of version>" d82113d39c4afbeaefc6c2c40ea2963d1df482e6
git push origin v0.28.13

Please sign in to comment.