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

@enhance/element

v1.4.4

Published

Enhance element base class

Downloads

287

Readme

Enhance element

HTML first base element class to help cut down on web component boilerplate.

Install

npm i @enhance/element

unpkg import enhance from 'https://unpkg.com/@enhance/element?module=true'

Codepen

Usage

<my-list heading="Todos"></my-list>

enhance('my-list', {
  api,
  attrs: [ 'heading' ],
  keys: [ 'todos' ],
  init(element) {
    console.log('My List: ', element)
  },
  render({ html, state }) {
    const { attrs={}, store={} } = state
    const { heading='' } = attrs
    const { todos=[{ title: 'You have not todos yet.' }] } = store
    const todoItems = todos
      .map(t => `<li>${t.title || ''}</li>`)
      .join('\n')

    return html`
    <h1>${heading}</h1>
    <ul>
      ${todoItems}
    </ul>
    <!-- debug -->
    <pre>
      ${JSON.stringify(state)}
    </pre>
    `
  },
  connected() {
    console.log('CONNECTED')
  },
  disconnected() {
    console.log('DISCONNECTED')
  }
})

api:Object

The api object is used in the Enhance state management flow. api object must expose a subscribe and unsubscribe methods that accept a listener function to be passed a state object when an update occurs.

keys:Array

The keys array contains strings corresponding to the keys on a state object. Your Enhance Element will only update when a specified key updates in the state object.

attrs:Array

The attrs array is where you declare what attributes you want your component to update

init:Function

The init function will be called once and is where you should run your setup code like adding event listeners, grabbing DOM references etc.

render:Function

The render function is a pure function that returns an HTML string

connected:Function

The connected function is called when your component is added to the page

disconnected:Function

The disconnected function is called when your component is removed to the page

shadow:Enum

The shadow property can be set to either open or closed and effects how the components shadow root is "encapsulated".

 enhance('my-shady',{
    attrs: [ 'message' ],
    shadow: 'open',
    render({ html, state }) {
      const { attrs={} } = state
      const { message='So shady' } = attrs
      return html`
      <p>
        ${message}
      </p>
      `
    }
  })