nim-plotly
nim-plotly copied to clipboard
macro for `%` JSON serialization
currently any time an attribute is added, the %
procs must be updated to include that attribute.
a macro that iterated over the fields and values would simplify this a lot.
@brentp not sure i understand, but *%
from std/json can do that: it can serialize (or reverse: https://nim-lang.github.io/Nim/json.html#overview-unmarshalling) objects and tuples directly, no need to iterate over fields
specifically: this could be replaced by: let foo = %* a
IIRC
func `%`*(a: Annotation): JsonNode =
## creates a JsonNode from an `Annotations` object depending on the object variant
result = %[ ("x", %a.x)
, ("xshift", %a.xshift)
, ("y", %a.y)
, ("yshift", %a.yshift)
, ("text", %a.text)
, ("showarrow", %a.showarrow)
]
I mean, for example, the ones the use ordered fields, as in: https://github.com/brentp/nim-plotly/blob/master/src/plotly/api.nim#L175