be-invoking
v0.0.4
Published
Invoke method on upstream peer element or the host.
Downloads
13
Maintainers
Readme
be-invoking (🕹️)
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.
Example 1a Invoking a host method on most common event (depending on context)
<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:
Example 1b
<mood-stone>
#shadow
<input disabled 🕹️='howAmIFeelingAboutToday on change'>
</mood-stone>
Example 1c
<mood-stone>
#shadow
<soul-searcher -engage-in-second-guessing></soul-searcher>
<input disabled 🕹️='-engage-in-second-guessing'>
</mood-stone>
Example 1d
<mood-stone>
#shadow
<soul-searcher></soul-searcher>
<input 🕹️='~soulSearcher:engageInSecondGuessing'>
</mood-stone>
Viewing Demos Locally
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.
Running Tests
> npm run test
Using from ESM Module:
import 'be-invoking/be-invoking.js';
Using from CDN:
<script type=module crossorigin=anonymous>
import 'https://esm.run/be-invoking';
</script>