Docs: /reference/rocket does not document how to invoke a registered action from outside the element
Summary
/reference/rocket documents how to register a local action via action(name, fn) and how to call it from inside the rendered markup (e.g. data-on:click="@copy()"), but it does not document how an external script or button calls a registered action on a Rocket element.
The bundle exposes a dispatchRocketAction(name, ...args) method on each Rocket custom element instance, but there is no reference page describing this API.
Current state of the docs
The Setup Context helpers table on /reference/rocket lists action(name, fn) as:
"Registers a local action callable from rendered markup."
There is no example of a button outside the component invoking action, nor any mention of dispatchRocketAction or the customElements.whenDefined(...) pattern needed when calling before the element has upgraded.
What the bundle actually exposes (v1.0.1)
Searching the v1.0.1 Pro bundle for dispatchRocketAction yields:
class x extends HTMLElement {
// ...
dispatchRocketAction(f, h, S, R, ...k) {
let T = this.#g.get(f);
if (T) return T({ host: this, props: this.#r, state: this.#i, el: h, evt: S }, ...k);
// bubbles to parent Rocket, falls back to global action, throws Error("Undefined Rocket action: ...")
}
}
So the only supported way to call a registered action from outside is:
document.querySelector('my-component').dispatchRocketAction('reset')
And before the element has upgraded:
customElements.whenDefined('my-component').then(() => {
document.querySelector('my-component').dispatchRocketAction('reset')
})
Suggested doc additions on /reference/rocket
- After the
action(name, fn) row in the Setup Context table, add a sub-section titled "Invoking actions from outside the component" with the dispatchRocketAction example above.
- Note the upgrade-timing pitfall: calling
dispatchRocketAction before customElements.define has registered the tag throws TypeError: dispatchRocketAction is not a function. Show the whenDefined recipe.
- Cross-link from the
/examples/rocket_* examples that rely on external action invocation (e.g. file-list / counter resets in third-party demos).
Context
This came up while implementing a Rocket component in a learning project; the data-on:click="@actionName()" style is well-documented, but external invocation took several rounds of bundle inspection to figure out. Memory of the pattern is now in our project notes, but it would be helpful for newcomers if it were on the reference page.
Docs:
/reference/rocketdoes not document how to invoke a registered action from outside the elementSummary
/reference/rocketdocuments how to register a local action viaaction(name, fn)and how to call it from inside the rendered markup (e.g.data-on:click="@copy()"), but it does not document how an external script or button calls a registered action on a Rocket element.The bundle exposes a
dispatchRocketAction(name, ...args)method on each Rocket custom element instance, but there is no reference page describing this API.Current state of the docs
The Setup Context helpers table on
/reference/rocketlistsaction(name, fn)as:There is no example of a button outside the component invoking
action, nor any mention ofdispatchRocketActionor thecustomElements.whenDefined(...)pattern needed when calling before the element has upgraded.What the bundle actually exposes (v1.0.1)
Searching the v1.0.1 Pro bundle for
dispatchRocketActionyields:So the only supported way to call a registered action from outside is:
And before the element has upgraded:
Suggested doc additions on
/reference/rocketaction(name, fn)row in the Setup Context table, add a sub-section titled "Invoking actions from outside the component" with thedispatchRocketActionexample above.dispatchRocketActionbeforecustomElements.definehas registered the tag throwsTypeError: dispatchRocketAction is not a function. Show thewhenDefinedrecipe./examples/rocket_*examples that rely on external action invocation (e.g. file-list / counter resets in third-party demos).Context
This came up while implementing a Rocket component in a learning project; the
data-on:click="@actionName()"style is well-documented, but external invocation took several rounds of bundle inspection to figure out. Memory of the pattern is now in our project notes, but it would be helpful for newcomers if it were on the reference page.