Stimulus: Why Stimulus does not look for the parent controller?

Created on 25 Feb 2018  路  1Comment  路  Source: hotwired/stimulus

Look at this example, which is on your repo index page:

<div data-controller="hello">
  <input data-target="hello.name" type="text">

  <button data-action="click->hello#greet">Greet</button>

  <span data-target="hello.output"></span>
</div>

This "framework" should be capable of detecting the current controller, since the click function is happening inside my controller scope, then call the method "hello" in that scope.

hello#get + data-controller="hello" just why?

Most helpful comment

Because scopes may be nested or intermingled with other scopes.

<div data-controller="hello goodbye">
  <button data-action="hello#respond">Say Hello</button>
  <button data-action="goodbye#respond">Say Goodbye</button>
</div>

This "framework" decided to avoid possible ambiguity by requiring an explicit and consistent naming convention.

>All comments

Because scopes may be nested or intermingled with other scopes.

<div data-controller="hello goodbye">
  <button data-action="hello#respond">Say Hello</button>
  <button data-action="goodbye#respond">Say Goodbye</button>
</div>

This "framework" decided to avoid possible ambiguity by requiring an explicit and consistent naming convention.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ngan picture ngan  路  3Comments

incompletude picture incompletude  路  3Comments

paulozoom picture paulozoom  路  4Comments

chocnut picture chocnut  路  4Comments

dwightwatson picture dwightwatson  路  3Comments