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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@wesib/generic

v2.0.2

Published

Wesib: Generic Components

Readme

Wesib: Generic Components

NPM Build Status Code Quality Coverage GitHub Project API Documentation

Component Shares

Shares allow enclosing component to share and update some data with nested ones.

To share something:

  1. Create a Share class (or its subclass) instance.

    import { Share } from '@wesib/generic';
    
    const MyShare = new Share<MyData>('my-share');
  2. Amend enclosing component's property containing a data to share with @Shared() decorator:

    import { Shared } from '@wesib/generic';
    import { Component } from '@wesib/wesib';
    
    @Component('my-container')
    class MyContainerComponent {
      @Shared(MyShare)
      mySharedData?: MyData;
    
      // Update the `mySharedData` property when the data is ready to be shared.
    }
  3. Consume the shared data in nested component.

    import { AfterEvent } from '@proc7ts/fun-events';
    import { Component, ComponentContext } from '@wesib/wesib';
    
    @Component('my-nested')
    class MyNestedComponent {
      readonly myContainerData: AfterEvent<[MyShare?]>;
    
      constructor(context: ComponentContext) {
        this.myContainerData = MyShare.valueFor(context);
      }
    
      // Consume shared data when it is reported by `myContainerData`.
    }

The sharing mechanism works despite sharer and consumer components instantiation order.

Buffered Fragment Rendering

Buffered rendering is useful when there is a lot of content to add to the page. This content may even contain nested components.

For the sake of performance, it is reasonable to add such content to DocumentFragment first, initialize nested components, and then add already rendered fragment to the document. E.g. using requestAnimationFrame.

A @RenderFragment() amendment (and decorator) handle this:

import { Attribute, Component } from '@wesib/wesib';
import { FragmentRendererExecution, RenderFragment } from '@wesib/generic';

@Component('my-list')
class MyList {
  /**
   * Declares `item-list` attribute.
   *
   * Contains comma-separated `name=value` pairs.
   */
  @Attribute()
  itemList: string = '';

  /**
   * Renders item list.
   *
   * This method will be called each time the `item-list` attribute updated.
   */
  @RenderFragment()
  render({ content }: FragmentRendererExecution) {
    // `content` is a `DocumentFragment` instance.
    // This method fills this `content` on each call.
    // The `content` will be added to the document at proper time.
    const ul = content.appendChild(document.createElement('ul'));

    for (const item of this.itemList.split(',')) {
      const [name, value] = item.split(item, '=');
      const li = ul.appendChild(document.createElement('li'));

      // Each `my-item` component will be settled after this method call, and _before_ it is added to the document.
      // If `my-item` renders its own content, this content will be added to this component's `content` fragment,
      // rather directly to document.
      const link = li.appendChild(document.createelement('my-item'));

      link.setAttribute('name', name);
      link.setAttribute('value', value);
    }
  }
}

HTTP Fetch

An HttpFetch is a function available is bootstrap context. It resembles the Fetch API, but returns an OnEvent event sender, that sends a Response event(s), rather a promise resolving to the one.

An HttpFetchAgent can be provided in bootstrap context to intercept HTTP requests. E.g. to modify the request and/or response.