-
|
Hi, I'm trying to evaluate nickel for a use case that involves deep merging. Imagine a set of variables use to theme a website or an app with a structure along those lines: given those base definitions, then I'd like to be able to define a set of differend "designs", each one extending the base and the set of themes, overriding only what is needed. e.g. I've been struggling to get the result I need, If you try this code you'll notice that the "dark" theme within Am I in the right direction? What is the idiomatic way to achieve this kind of "inheritance"? Additionally I'd like to eventually explore some validation aspects:
I am curious to hear if you have suggestion or even completely different approaches. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
|
I think your approach is basically fine, but you've misunderstood the behavior of I'm sorry that the previous sentence isn't very clear; I'm having trouble figuring out a better way to explain it. But here's an example: because the default value of In other words, you should probably have the |
Beta Was this translation helpful? Give feedback.
-
I think there was some discussion about having some metadata that could propagate recursively, but I can't find it now. In any case, you currently need to put it on every field. About the validation, I'd probably define something like Theme = {
color.text.primary
| doc "primary color"
| String,
color.text.secondary
| doc "secondary color"
| String,
# etc
}and then apply this contract to each theme. If the names of the themes are also fixed, you could also do Themes = {
base | Theme,
dark | Theme,
light | Theme, # etc
}and then you can validate your themes with |
Beta Was this translation helpful? Give feedback.
I think your approach is basically fine, but you've misunderstood the behavior of
default: sincedarkis marked asdefaultwithinthemes, when you mergethemeswith{ dark = blah }, theblah"wins" and completely overwrites the previous settings inthemes.dark.I'm sorry that the previous sentence isn't very clear; I'm having trouble figuring out a better way to explain it. But here's an example:
because the default value of
ais overridden by the higher-priority value{ b = 2 }. If you want to do recursive merging instead of overriding, you need the twoas to have the same priority instead of having one as the…