Invoke method on upstream peer element or the host.
Note
This element enhancement took some inspiration from the original form that the invoker commands proposal adopted as well as countless frameworks. Once that becomes built into the platform (hopefully), definitely consider adopting that built-in technique before using this as a last resort.
<mood-stone>
#shadow
<input disabled be-invoking='howAmIFeelingAboutToday'>
</mood-stone>
What this does:
- Removes the disabled attribute after hydrating.
- Listens by default for "input" events.
- Invokes host-element's howAmIFeelingToday method only when the input element dispatches "input" event. If adorning a button element, it will invoke the method on clicking.
It passes in two arguments:
- The instance of whatever element is being invoked, just in case that is helpful.
- The event that triggered the action.
Note that the word "be-invoking" is a bit long. It is easy to choose your own name, as demonstrated by this file.
In the rest of the examples, we will use the emoji 🕹️ to represent "be-invoking" just for the fun of it.
To specify a different event to act on:
<mood-stone>
#shadow
<input disabled 🕹️='howAmIFeelingAboutToday on change'>
</mood-stone>
<mood-stone>
#shadow
<soul-searcher -engage-in-second-guessing></soul-searcher>
<input disabled 🕹️='-engage-in-second-guessing'>
</mood-stone>
<mood-stone>
#shadow
<soul-searcher></soul-searcher>
<input 🕹️='~soulSearcher:engageInSecondGuessing'>
</mood-stone>
Any web server that can serve static files will do, but...
- Install git.
- Fork/clone this repo.
- Install node.js.
- Open command window to folder where you cloned this repo.
-
npm install
-
npm run serve
- Open http://localhost:3030/demo/ in a modern browser.
> npm run test
import 'be-invoking/be-invoking.js';
<script type=module crossorigin=anonymous>
import 'https://esm.run/be-invoking';
</script>