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

Add ability to invoke Commands with a Stimulus controller #106

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

hopsoft
Copy link
Owner

@hopsoft hopsoft commented Oct 3, 2023

This PR is exploratory, but may prove quite powerful and convenient. It introduces a new optional Stimulus controller that can be used to invoke commands in addition to event delegation. Note that event delegation is still used under the hood.

Trigger a command based on an explicit Stimulus controller.

<a href="#" 
  data-controller="command" 
  data-action="click->command#invoke:capture"
  data-command-name-value="MyCommand#perform">
  Trigger a TurboBoost Command
</a>

Submit a form and invoke a command at the same time. All form params will be available to the controller and command server side. Note that this will perform a real form submit... not shenanigans to approximate one.

<form id="my-form">
  ...
</form>

<a href="#" 
  data-controller="command" 
  data-action="click->command#invoke:capture"
  data-command-form-value="my-form"
  data-command-name-value="MyCommand#perform">
  Submit the form and Trigger a TurboBoost Command
</a>

I believe this will satisfy the requested feature from #83

@hopsoft hopsoft added the enhancement New feature or request label Oct 3, 2023
@hopsoft hopsoft changed the title Add ability to drive Commands from a Stimulus controller Add ability to invoke Commands from a Stimulus controller Oct 3, 2023
@hopsoft hopsoft changed the title Add ability to invoke Commands from a Stimulus controller Add ability to invoke Commands with a Stimulus controller Oct 3, 2023
@hopsoft
Copy link
Owner Author

hopsoft commented Oct 3, 2023

We may need to remove capture from the event delegation for this to work reliably. 🤔


On second thought, I don't think this will be necessary.

@julianrubisch
Copy link
Collaborator

My initial thought looking at this: Let's add a helper that writes that markup for you?

@hopsoft
Copy link
Owner Author

hopsoft commented May 22, 2024

Note

Related to #83, Hopefully I can get some time to refocus on this effort soon. 🤞🏻

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

Successfully merging this pull request may close these issues.

2 participants