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

aggregator-fn

v0.0.40

Published

Evaluate expressions in inline script tag.

Downloads

21

Readme

Published on webcomponents.org

Actions Status

aggregator-fn

<aggregator-fn> (or <ag-fn> for short) is a non-visual custom element that aggregates properties together using an inline JS expression, and which can act as a "piping" processor between two or more elements.

It is most useful for markup-centric applications, consisting of web components that are not controlled by some state managed component container -- for example a "peer-to-peer" binding framework.

The initial motivator for this component is being able to build url's from a form consisting of input elements -- declaratively.

See form-matter for an alternative.

Syntax:

<aggregator-fn><script nomodule>
    ({operation, expression}) => `https://newton.now.sh/${operation}/${encodeURI(expression)}`
</script></aggregator-fn>

or

<ag-fn><script nomodule>
    ({operation, expression}) => `https://newton.now.sh/${operation}/${encodeURI(expression)}`
</script></ag-fn>

does the following:

  1. Dynamically attaches properties to the aggregator-fn element for each of the function arguments -- "operation" and "expression" in this case.
  2. Any time any of the property values change, the aggregator function is evaluated (allowing for some debouncing), and the result is stored in the element's value property. An event, "value-changed" is fired every time the value changes.

aggregator-fn doesn't make much sense standing on its own. Let's see how we can use it in the markup below, to handle sending a request to the Newton Api Advanced Math microservice.

<div>
    <label for=operation>Operation:</label>
    <input id=operation value=integrate>
    <!-- "p-d" = pass down -->
    <p-d on=input to=[-operation] m=1 init-val=value></p-d>
    <label for=expression>Expression:</label>
    <input id=expression value="x^2">
    <p-d on=input to=[-expression] m=1 init-val=value></p-d>
    <aggregator-fn -operation -expression><script nomodule>
        ({operation, expression}) => `https://newton.now.sh/api/v2/${operation}/${encodeURI(expression)}`
    </script></aggregator-fn>
    <p-d on=value-changed to=[-href] m=1 as-str-attr></p-d>
    <k-fetch -href as=json></k-fetch>
    <p-d on=fetch-complete to=[-object] m=1></p-d>
    <json-viewer -object></json-viewer>
    <script type=module>
        import 'https://cdn.skypack.dev/[email protected]?min';
        import 'https://cdn.skypack.dev/[email protected]?min';
        import 'https://cdn.skypack.dev/[email protected]?min';
    </script>
    <script type=module src=https://unpkg.com/@power-elements/[email protected]/json-viewer.js?module></script>
</div>

Demo

Post IE/11 Support

Accessing the custom element itself, containing host

In some circumstances, you may need the aggregator function to have access to the context from which it is being called. To do this, add an argument, "self":

<ag-fn>
    <script nomodule>
        ({a, b, c, self}) => {
            console.log(self);
            return a + b + c;
        }
    </script>
</ag-fn>

You can also reference the host component if it is available. The host is obtained via self.getRootNode().host. This makes sense if aggregator-fn/ag-fn is used within a traditional web component that uses Shadow DOM. If it is used inside a web component that doesn't use shadowDOM, or some other containing DOM element you want to give special access to and call it "host", use property/attribute hostSelector/host-selector.

API Reference

Viewing Your Element

  1. Install node.js
  2. Install git. Fork or clone this repo.
  3. From a command window, navigate to the folder created in step 2.
  4. Now run:
$ npm run serve

Running Tests

$ npm run test