Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request changes Stimulus to respect the ordering of action descriptors in
data-action
attributes, guaranteeing that actions are invoked from left to right, and that an action on the left can stop an event to prevent invocation of actions on the right.At a high level, we do this by:
index
property toAction
, representing the action’s position in thedata-action
attributeContext
level up to theApplication
levelImplementation-wise, this branch:
TokenObserver
to emitToken
s, which have anindex
property in addition to a stringcontent
. IntroducesValueObserver
as a high-level interface for observing tokens with value semantics (scopes and actions, in Stimulus’ case).TokenListObserver
and obviates much of the work in TokenObserver #110, which was designed to support a particular implementation of the abstract class names feature planned for Stimulus 1.1 that we ultimately decided not to use.index
property toAction
, representing the index of its corresponding token in thedata-action
attribute. ReplacesAction.forElementWithDescriptorString()
withAction.forToken()
.EventListener
to a new class,Binding
, which represents the connection between aContext
and anAction
. ABinding
is responsible for invoking an action but not for registering the underlying DOM event listener.EventListener
class which wraps anEventTarget
and an event name and maintains a set ofBinding
s. When invoked, anEventListener
subsequently invokes each of its bindings in index order. It also extends theEvent
object in order to detect and support calls tostopImmediatePropagation()
.ActionObserver
withBindingObserver
, whose delegate receives notifications when bindings connect and disconnect.Dispatcher
, which manages an app-wide registry mappingBinding
s toEventListener
s. EachApplication
has a singleDispatcher
instance which acts as the delegate for allActionObserver
s.