Class TriggerSupport
java.lang.Object
com.vaadin.flow.internal.nodefeature.NodeFeature
com.vaadin.flow.internal.nodefeature.ServerSideFeature
com.vaadin.flow.component.trigger.internal.TriggerSupport
- All Implemented Interfaces:
ConfigContext,Serializable
Per-element store of triggers, actions, outputs and bindings for the trigger
API. Lazily instantiated by
on(Element). Emits client snapshots via
Element.executeJs(String, Object...) on every binding change and on
each (re-)attach.
For internal use only.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionTriggerSupport(StateNode node) Creates a TriggerSupport feature for the given state node. -
Method Summary
Modifier and TypeMethodDescriptionvoidbind(AbstractTrigger trigger, Action[] actions) Adds a binding from a trigger to a sequence of actions.voiddispatchMirrorForTest(int actionId) Invokes the mirror dispatch for the given action id, as if the client had reported the action as fired.Element[]Parameter array (excluding the host at index 0) for testing.@Nullable AbstractActiongetAction(int id) Looks up an action by id.getHost()The host element this snapshot belongs to.static TriggerSupportGets or creates the TriggerSupport for the given component's root element.static TriggerSupportGets or creates the TriggerSupport for the given element.intreferenceElement(Element element) Returns a parameter index for the given element to be passed alongside the snapshot.intregisterAction(AbstractAction action) Registers an action with this support, assigning it an id, deduping by identity.intregisterOutput(Output<?> output) Registers an output with this support, assigning it an id, deduping by identity.intregisterTrigger(AbstractTrigger trigger) Registers a trigger with this support, assigning it an id.voidremoveTrigger(AbstractTrigger trigger) Removes a trigger and all bindings created from it.voidSchedules a fresh client snapshot for the host to be emitted on the nextbeforeClientResponseflush.tools.jackson.databind.node.ObjectNodeBuilds the snapshot for testing.Methods inherited from class com.vaadin.flow.internal.nodefeature.ServerSideFeature
collectChanges, forEachChild, generateChangesFromEmptyMethods inherited from class com.vaadin.flow.internal.nodefeature.NodeFeature
allowsChanges, attachPotentialChild, detatchPotentialChild, getNode, onAttach, onDetachMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.trigger.internal.ConfigContext
referenceElement
-
Constructor Details
-
TriggerSupport
Creates a TriggerSupport feature for the given state node.- Parameters:
node- the node
-
-
Method Details
-
on
Gets or creates the TriggerSupport for the given element.- Parameters:
host- the element, notnull- Returns:
- the TriggerSupport instance, never
null
-
on
Gets or creates the TriggerSupport for the given component's root element.- Parameters:
host- the component, notnull- Returns:
- the TriggerSupport instance, never
null
-
registerTrigger
Registers a trigger with this support, assigning it an id.- Parameters:
trigger- the trigger, notnull- Returns:
- the assigned id
-
registerAction
Registers an action with this support, assigning it an id, deduping by identity.- Parameters:
action- the action, notnull- Returns:
- the assigned id
-
registerOutput
Registers an output with this support, assigning it an id, deduping by identity.- Specified by:
registerOutputin interfaceConfigContext- Parameters:
output- the output, notnull- Returns:
- the assigned id
-
referenceElement
Returns a parameter index for the given element to be passed alongside the snapshot. The host's own element is at index 0 (thethisof the executeJs invocation); other elements get sequential indices starting at 1.- Specified by:
referenceElementin interfaceConfigContext- Parameters:
element- the element to reference, notnull- Returns:
- the parameter index
-
bind
Adds a binding from a trigger to a sequence of actions.- Parameters:
trigger- the trigger, notnullactions- the actions, notnullor empty
-
removeTrigger
Removes a trigger and all bindings created from it.- Parameters:
trigger- the trigger, notnull
-
getAction
Looks up an action by id. Used when the client posts a server-side mirror back over theapplyServerSideEffectchannel.- Parameters:
id- the action id- Returns:
- the action, or
nullif unknown
-
getHost
Description copied from interface:ConfigContextThe host element this snapshot belongs to. Useful for outputs that install element-scoped subscriptions (e.g.SignalOutputviaElementEffect.effect).- Specified by:
getHostin interfaceConfigContext- Returns:
- the host element
-
scheduleSync
public void scheduleSync()Description copied from interface:ConfigContextSchedules a fresh client snapshot for the host to be emitted on the nextbeforeClientResponseflush. Used by outputs whose value may change between trigger fires (e.g. aSignalOutput). Idempotent within a request.- Specified by:
scheduleSyncin interfaceConfigContext
-
snapshotForTest
public tools.jackson.databind.node.ObjectNode snapshotForTest()Builds the snapshot for testing.- Returns:
- the snapshot
-
elementParamsForTest
Parameter array (excluding the host at index 0) for testing.- Returns:
- the secondary elements
-
dispatchMirrorForTest
public void dispatchMirrorForTest(int actionId) Invokes the mirror dispatch for the given action id, as if the client had reported the action as fired. For testing only.- Parameters:
actionId- the action id
-