-
Notifications
You must be signed in to change notification settings - Fork 49
Description
Context Structs are not all pub, making replacing just one piece of a sub-component much more difficult when needing customizations not supported out of the box.
I'm arguing that any context struct used by a component should be public, and at very least any fields used by any component should also be public as well. The issue this solves is the following:
If you want to replace the logic in just one element while keeping everything else the same, you are currently unable to do that in many cases.
As an example, lets say I want to relace the SingleCalendarDay component to change something about the way it is rendered or calculated.
The following contexts are used, at a minimum:
BaseCalendarContextpub with private fieldsSingleCalendarDayuses the private fieldstoday,disabled,focused_dateas an example
CalendarViewContextprivateCalendarContextpub with private fields
The original component can then access information needed to build its view, but if an end user wants to replace just this one inner component they end up needing to replace everything so they can provide contexts that they actually have access to, in order to just get back to that base functionality. In the end if you need to slightly modify just one sub-component you end up needing an entire fork essentially of at least that component in order to replace it.
Ideally, how I think it should work is I should be able to copy the entirety of the SingleCalendarDay component into my project, pull in all the required imports, and that should then just work. At that point I can then make any changes necessary. This currently does not work due to these private structs/fields.
The reason this then spreads to having to replace all the components is because if I make my own version of the context in my create, that is not the context actually being provided by the parent components still under this repo.
I would argue with the way the dx components add ___ command adds the components to your crate with shims pointing to this repo, it is trying to set you up so that it is easy to replace just one subcomponent, but due to the contexts issue, in practice this is not actually possible without replacing everything.
Obvious downsides:
- All of these context structs become part of the public interface for this crate, meaning breaking changes for these structs are public breaking changes.
Alternate Solutions:
- Make context structs pub, but add getter and/or setter functions for fields where necessary to allow for future internal changes
- User forks/venders the entire repo when needing to make small changes to subcomponents
- User copies all subcomponents and contexts into your crate for that one component, to re-build up the original functionality, just to make the small change.