be-scoped
TypeScript icon, indicating that this package has built-in type declarations

0.0.28 • Public • Published

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>

Package Sidebar

Install

npm i be-scoped

Weekly Downloads

13

Version

0.0.28

License

MIT

Unpacked Size

7.59 kB

Total Files

5

Last publish

Collaborators

  • bahrus