Replies: 1 comment
-
Best Regards,
P.Kushal,
3056997282.
… On Nov 23, 2021, at 1:31 PM, juanjonol ***@***.***> wrote:
Hi everyone! I just found this library and I like it a lot! I would like to contribute, but I have a few doubts about the current implementation.
One of the big changes of the new v2 version seems to be that it allows to initialise a chart using an @EnvironmentObject. This seems better than v1, where a chart requires static data and as such it won't automatically update when that data changes. But what I don't understand is, why an @EnvironmentObject is used instead of an @observableobject?
As I see it, @EnvironmentObject is better suited for pieces of data that are common to a whole app (current colorScheme, font...), but in this case we could have hundred of charts with different data. Also, because the data isn't set as part of the init(), its very easy to forget setting it, which could make the whole app crash (if .enviromentObject() isn't called on any parent View)1, or even worse, it could make a chart use unexpected data (if a parent View calls .enviromentObject() for an unrelated chart).
Keeping all this in mind, I think it would make more sense to:
Keep an init() similar to the one on v1, that forces setting the actual data that will be used by the chart (for example, BarChartView(data:)), but with the requirement that this data is an @observableobject.
Keep View Modifiers like .chartStyle() to modify the View on a SwiftUI-idiomatic way, but without using @EnvironmentObject internally.
Finally, maybe a few @EnvironmentObjects could be added, for example a defaultChartStyle in case no chartStyle is set during the chart's initialisation.
Is there anything I'm missing? Would this proposal make sense?
Thank you!
Footnotes
This literally happened to me, before I found the v2 beta documentation. ↩
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi everyone! I just found this library and I like it a lot! I would like to contribute, but I have a few doubts about the current implementation.
One of the big changes of the new v2 version seems to be that it allows to initialise a chart using an
@EnvironmentObject
. This seems better than v1, where a chart requires static data and as such it won't automatically update when that data changes. But what I don't understand is, why an@EnvironmentObject
is used instead of an@ObservableObject
?As I see it,
@EnvironmentObject
is better suited for pieces of data that are common to a whole app (currentcolorScheme
, font...), but in this case we could have hundred of charts with different data. Also, because the data isn't set as part of theinit()
, its very easy to forget setting it, which could make the whole app crash (if.enviromentObject()
isn't called on any parent View)1, or even worse, it could make a chart use unexpected data (if a parent View calls.enviromentObject()
for an unrelated chart).Keeping all this in mind, I think it would make more sense to:
init()
similar to the one on v1, that forces setting the actual data that will be used by the chart (for example,BarChartView(data:)
), but with the requirement that this data is an@ObservableObject
..chartStyle()
to modify the View on a SwiftUI-idiomatic way, but without using@EnvironmentObject
internally.@EnvironmentObjects
could be added, for example adefaultChartStyle
in case nochartStyle
is set during the chart's initialisation.Is there anything I'm missing? Would this proposal make sense?
Thank you!
Footnotes
This literally happened to me, before I found the v2 beta documentation. ↩
Beta Was this translation helpful? Give feedback.
All reactions