-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve how groups of reactive variables are managed #276
Comments
We could probably just modify the very first method for stipple_parse to achieve that without any type restriction function stipple_parse(::Type{T}, value) where T
if isstructtype(T)
T([value[String(f)] for f in fieldnames(T)]...)
else
Base.parse(T, value)
end
end |
We could even do this recursively: T([stipple_parse(Ft, value[String(f)]) for (f, Ft) in zip(fieldnames(T), fieldtypes(T))]...) |
Finally, I'd also like to cover structs, that are defined via function stipple_parse(::Type{T}, value) where T
if isstructtype(T)
ff = [String(f) for f in fieldnames(T)]
kk = String.(keys(value))
# if all fieldnames are present, generate the type directly from the fields
if all(ff .∈ Ref(kk))
T([stipple_parse(Ft, value[String(f)]) for (f, Ft) in zip(ff, fieldtypes(T))]...)
# otherwise, try to generate it via kwargs, e.g. when the type is defined via @kwdef
else
T(; (Symbol(k) => v for (k,v) in value)...)
end
else
Base.parse(T, value)
end
end |
This will break any existing parse methods for struct types, but I'm currently not aware of any structtypes that we are using in Stipple via parse. |
@essenciary What do you think? |
Not sure it helps here, but JSON3 StructTypes has OrderedStruct which ensures any arbitrary order of items is serialized/deserialized. But it’s probably not worth the extra complexity of doing the JSON intermediate representation. |
I use |
Minor sidetrack -- where can I learn more about triggering updates with I searched everywhere in the repo and cannot find its definition to see how it works. I'm referring to @PGimenez 's snippet above:
|
That's still poorly implemented. |
done in bda3e9f |
When the number of reactive variables grows large, managing them becomes difficult. We should have a way to group them to make the code more succint, and also make it easier to bring existing structures into an app. As of now we can use mixins or define a struct + its own
Stipple.stipple_parse
implementation, as seen in this Discord threadPerhaps we could have a generic struct type built into Stipple so that users wouldn't need to define their own
stipple_parse
for each type. I've created a MWE for aReactiveStruct
abstract type. It works but there are two caveats:stipple_parser
calls the constructor with arguments in this order. This could be solved with some more complicated logicThe text was updated successfully, but these errors were encountered: