Content
Stimulus in Plugin
Added by Niclas UNIBE about 1 month ago
Hei there!
I'm currently working on a plugin and I would like to use hotwire stimulus.
I don't see how to do this from the documentation or sample plugins.
When using the dynamic loading of the stimulus controller, the plugin's controller file is not found (not surprisingly).
To me it seems like the problem is that the stimulus OpApplicationController
needs the dynamically loaded stimulus controller to be in the <op-core-root>/frontend/src/stimulus/controllers/dynamic
directory.
However the plugin frontend linking symlinks to <op-core-root>/frontend/src/app/features/plugins
.
So there is no way to import the symlinked stimulus controller files.
So I see two solutions:
- Symlinking the plugin
controllers/dynamic
directory to the OpenProject core's stimulus controllers directory (plus probably adjusting theOpApplicationController
a bit) - Using stimulus'
application.register()
function to add the plugins controller in a JS script in the plugin.
The first solution would be a lot nicer since it ties in nicely with the symlinking used for angluar already, but requires a change in OP.
The second approach feels a bit like a hack, but wouldn't require a change in OP.
I could make a merge request for option 1 if that is a favorable solution.
What is your opinion?
PS: I really like the OP code in general. It's challenging to understand, but I learn so much from it!
Replies (1)
Another solution I got working is to create a second stimulus instance.
This is of course very dissatisfying and I also loose the "dynamic" loading of stimulus controllers implemented in OP.
What I did is starting another stimulus application like this:
and in my erb
The
hello.controller.ts
ist the stimulus controller from the official tutorial example.