dbuezas / lovelace-plotly-graph-card

Highly customisable Lovelace card to plot interactive graphs. Brings scrolling, zooming, and much more!
410 stars 19 forks source link

[internal] on demand pure functions #246

Open dbuezas opened 1 year ago

dbuezas commented 1 year ago

Describe the solution you'd like Users may want to change attributes like texttemplate or hovertemplate and still make them depend on other defaulted props (e.g unit_of_measurement) which are also funcitons. This breaks the delicate order of evaluation and results in an error like "this fn can't use this param because it is also a fn and it should be defined before".

To work around that: implement pure functions for internal use of the defaults. These should have no side effects (not modify any parameter, like vars), which will allow to safely call them on demand (even if defined later) With that

Additional context I tried it once and it worked, but dropped it because the code got kind of messy. I think it would be best if the functions are also ensured to be called only once by adding it to the incrementally parsed config once evaluated. Ideally pure functions should be available to users for corner cases, but not documented to discourage their usage as they are a somewhat complex/unintuitive/brittle concept.

dbuezas commented 1 year ago

Actual failure case example in #243