I’m learning stimulus and one detail that jumped to my mind was the differences between the API for handling targets (i.e.
this.nameTarget) and the API for “state data” (
It would seem to me that using a namespace for targets (
this.targets.get('index')) could have several advantages over the current implementation:
this.targetswould allow lazy loading:
targetswould start “empty” and fetch each target when it is first used instead on fetching them all from the DOM on connection (as I am assuming is done now).
- The previous point would allow removing the static
targetsvariable from the controllers.
- There would be a place to add common functions for targets. Iterate over all targets, for example.
- The API would look more cohesive and, in my opinion, easier to learn.
I think I might be missing something crucial.
Thanks for releasing this library to the world!