bahrus / be-scoped

Create an EventTarget associated with the adorned element that can hold scoped state.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

be-scoped

Create an EventTarget associated with the adorned element that can hold scoped state.

<div id="scoped" be-scoped='{"count": 30}'></div>

...results in:

console.log(scoped.beEnhanced.beScoped.scope.count === 30)
//true

To subscribe to changes to the scope:

await customElements.whenDefined('be-enhanced');
const beScoped = await scoped.beEnhanced.whenResolved('be-scoped');
beScoped.scope.addEventListener('count', e => {
    console.log(e.detail);
});

Adorning a custom element

If the desire is to add "scoping" to a custom element, use be-propagating instead.

Playwright Tests NPM version

Size of package, including custom element behavior framework (be-enhanced/be-hive):

How big is this package in your project?

Size of new code in this package:

Viewing Locally

  1. Install git.
  2. Fork/clone this repo.
  3. Install node.
  4. Open command window to folder where you cloned this repo.
  5. npm install

  6. npm run serve

  7. Open http://localhost:3030/demo/ in a modern browser.

Importing in ES Modules:

import 'be-exportable/be-scoped.js';

Using from CDN:

<script type=module crossorigin=anonymous>
    import 'https://esm.run/be-scoped';
</script>

About

Create an EventTarget associated with the adorned element that can hold scoped state.

License:MIT License


Languages

Language:TypeScript 46.8%Language:JavaScript 39.2%Language:HTML 14.0%