npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

be-a-beacon

v0.0.70

Published

be-a-beacon is an HTML Element enhancement that causes the HTMLTemplate (or any other) element it adorns to emit bubbling event 'i-am-here", the moment it is connected to the live DOM tree. It is important to note that be-a-beacon is a special type of cu

Downloads

471

Readme

be-a-beacon (🗽)

be-a-beacon is an HTML Element enhancement that causes the HTMLTemplate (or any other) element it adorns to emit bubbling event 'i-am-here", the moment it is connected to the live DOM tree. It is important to note that be-a-beacon is a special type of custom enhancement -- one that only should be activated in the live DOM tree, not during template instantiation. During template instantiation, we already know everything that is in the template via simple css queries -- it is a closed system. be-a-beacon is specifically tailored for situations where elements arrive on the scene unexpectedly -- while the server-rendered HTML is streaming, or when fragments are added when conditions are warranted in the browser (i.e. lazy loading).

<div be-a-beacon>
    ...
</div>

The markup above is the "canonical" name, associated with this package name.

To use a shorter name, in a more closed, informal environment where conflicts between libraries can be easily avoided, we can define a file that customize3s the name. For example, this alternative allows us to use 🗽 instead:

<div 🗽>
    ...
</div>

Spell out the name of the event

To specify a different event name, set the attribute to the name ("type") of the event you would like it to emit:

<section>
    ...
    <div be-a-beacon=last-div-at-your-service>
        ...
    </div>
</section>
oSection.addEventListener('last-div-at-your-service', e => {
    console.log(e.target);
})

Shorter name

be-a-beacon is the formal canonical name of this enhancement. IN less formal settings, where clashes between different libraries are less likely, you can reference an alternative file, 🗽.js, and use a much shorter name:

To see how easy it is to define your own name, see the file that registers this alternative name.

Announce the presence of the id of the element

This is useful, for example, for bundling HTML includes

<section>
    ...
    <template id=b0735b7a-84d1-42e9-b3b8-e24cb88f5985 🗽=#>
        ...
    </template>
</section>

So the special value of "#" means emit event with the name specified by the id.

Playwright Tests NPM version

Size of package, including custom element behavior framework (be-decorated):

How big is this package in your project?

Size of new code in this package:

Use cases

  1. be-a-beacon provides a similar, but slightly different solution to a current limitation of the platform -- we don't know when a DOM element has finished parsing. The solution this component provides is an alternative to the solution spelled out here.

The difference is that this solution doesn't require a separate web component, but can simply "enhance" the last DOM element of the stream. The template element might be a good element to use be-a-beacon on, because the template element can be used universally -- it is one of the few elements that can appear in many more places without violating HTML decorum. In particular, it can appear inside a table element without being rudely ejected:

<table>
    <thead>
        ...
    </thead>
    <tbody>
        ...
    </tbody>
    <template be-a-beacon></template>
</table>

However, be-a-beacon can adorn any element, not just the template element. If adorning a custom element, you will need to prefix the attribute with "enh-by":

<my-fragment>
    ...
    <my-custom-element enh-by-be-a-beacon></my-custom-element>
</my-fragment>
  1. If a div element (say) is populated by a (streaming) fetch request, and that populating is done numerous times based on user interaction / timing events, then the placement of the beacon at the end of the stream can be used instead of a mutation observer to indicate, for example, that some content that should be derived from the contents of the DOM is ready to be generated.

  2. If a component wishes to provide its own default light children, in the event that the consumer doesn't provide their own, a cue is needed to know when no light children will be provided.

Viewing Locally

Any web server that serves static files (html, css, js) will do but...

  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/dev in a modern browser.

Importing in ES Modules:

import 'be-a-beacon/be-a-beacon.js';

Using from CDN:

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