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

ezcomponent

v1.0.2

Published

![EZComponent](https://i.imgur.com/QCKq3Jks.jpg)

Downloads

5

Readme

EZComponent

EZComponent

EZComponent is a library for building web components created by Alex Merced of AlexMercedCoder.com/devNursery.com, creator of other web component based libraries like MercedUI, AMPonent, funComponent and more.

To generate the official webpack based ezcomponent starter

npx create-ezcomponent-app projectName

Installation

npm

npm install ezcomponent

ESModule URL (for deno or browser)

https://res.cloudinary.com/dithdroai/raw/upload/v1609642167/libraries/ezcompmodule_p8vfdl.js

Non-Module URL (for standard script tags)

https://res.cloudinary.com/dithdroai/raw/upload/v1609644264/libraries/ezcomp_c67pm6.js

How It Works

You create components by using the ezcomponent function and passing it a config object. Here is an example...

ezcomponent({
    name: "my-component",
    render: (info, props, component) => `<h1>${props.hello}</h1>`
})

then can just be used in your html like so!


<body>
    <my-component hello="Hello World"></my-component>
</body>

The Config Object

The ezcomponent function takes an object as its one argument. Below are the properties that can be passed in.

Some terminology

  • info objective with reactive data to use in your component (like state in react), can be updated using the component.update function which then triggers another render of the components template.

  • props information passed to the component in the form of tag attributes

  • component a reference to the component instance passed into all the methods definable in the config object

name

This is the name of the component, must be kebab case ("kebab-case").

render

This is a function that must return a template string, this is essentially the template the component will render.

signature

(info, props, component) => "<h1>This is the template</h1>"

styles

This is a function that must return a string of css styles to apply to your component

signature

(info, props, component) => `
h1 {
    color: red;
}
`

initial

This is a function that runs on the initial mounting of the component

signature

(info, props, component) => {
    console.log("This happens when the component is initially rendered")
}

postInitial

This is a function that runs after the initial render

signature

(info, props, component) => {
    console.log("This happens after the component is initially rendered")
}

preRender

This is a function that runs before every render

signature

(info, props, component) => {
    console.log("This happens before every render")
}

postRender

This is a function that runs after every render

signature

(info, props, component) => {
    console.log("This happens after every render")
}

disconnect

This is a function that runs when the component is removed from the screen

signature

(info, props, component) => {
    console.log("This happens when component is removed")
}

Lifecycle

When a component is loaded initially this is the order that things

  • info is set
  • props is set
  • initial is run
  • preRender is run
  • render is run
  • postRender is run
  • postInitial

When the component.update function is used to update the info here is what happens

  • info is updated
  • props is updated
  • preRender is run
  • render is run
  • postRender is run

Design Tips

  • Any methods you want to add to the component should be defined in initial so they are available to the other methods.

  • Any event listeners should be configured in postRender so the event listener are re-established after re-rendering.

Example for Reference

      ezcomponent({
        name: "my-component",
        info: {
          count: 1,
        },
        styles: (info, props, el) => {
          return `
          button {
              background-color: red;
              color: white;
              `;
        },
        render: (info, props, el) => {
          return `<button>${info.count}</button>`;
        },
        initial: (info, props, el) => {
          console.log("initial");
        },
        preRender: (info, props, el) => {
          console.log("pre-render");
        },
        postRender: (info, props, el) => {
          console.log("post-render");
          el.shadowRoot
            .querySelector("button")
            .addEventListener("click", () => {
              el.update({ count: info.count + 1 });
            });
        },
        disconnect: (info, props, el) => {
          console.log("disconnect");
        },
        postInitial: (info, props, el) => {
          console.log("postInitial");
        },
      });