Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the Stimulus Standard Library #1

Open
tonysm opened this issue Aug 2, 2022 · 1 comment
Open

Implement the Stimulus Standard Library #1

tonysm opened this issue Aug 2, 2022 · 1 comment

Comments

@tonysm
Copy link
Collaborator

tonysm commented Aug 2, 2022

The folks at the hotwired/stimulus-rails gem are experimenting with a Stimulus standard library. I think that's a neat idea and want to explore it here once it gets merged there.

@tonysm
Copy link
Collaborator Author

tonysm commented Aug 2, 2022

I've got an initial implementation here, but I'm gonna wait to see how the Rails version will play out.

One thing I'm not so sure about is that eager loading seems to work when registering controllers from multiple places:

eagerLoadControllersFrom("controllers", application)
eagerLoadControllersFrom("std", application)

But lazy-loading like below works, but triggers a console error (it tries to register all controllers twice, one for each call of the lazyLoadControllersFrom function:

lazyLoadControllersFrom("controllers", application)
lazyLoadControllersFrom("std", application)

The error I get is the following:
Screen Shot 2022-08-01 at 22 56 20

I have two controllers being used in that page: one called hello and another called toggle-class (took it from the Rails branch).

One idea I had was to try changing the stimulus-loading to take an array as for the "under" param, so we could implement this like:

lazyLoadControllersFrom(["controllers", "std"], application)

Which would only fail the controller registration if it fails for both "packages". Not sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant