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

Allow for default method for controller actions #756

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Commits on Mar 16, 2024

  1. Allow for default method for controller actions

    This allows for actions to omit the method. When the method is omitted
    stimulus will use `_` as the method name. This will make it simpiler to
    use single method controllers.
    
    For example if we have a controller that disables an element before we
    would write something like this:-
    
    ```html
      <button data-action="click->disable#disable">Disable on click</button>
    ```
    
    ```js
    class DisableController extends Controller {
      disable({target}) {
        target.disabled = true
      }
    }
    ```
    
    After we can shorten the `data-action` attribute like this:-
    
    ```html
      <button data-action="click->disable">Disable on click</button>
    ```
    
    ```js
    class DisableController extends Controller {
      _({target}) {
        target.disabled = true
      }
    }
    ```
    
    This makes it easier for developers to write the controller as they can
    give the controller a clear name and not have to construct a name for
    the method when its not needed.
    pythonandchips committed Mar 16, 2024
    Configuration menu
    Copy the full SHA
    ae444bf View commit details
    Browse the repository at this point in the history