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

picocomponent

v2.1.0

Published

Teeny tiny component system

Downloads

21

Readme

picocomponent

Build Status Standard - JavaScript Style Guide

Teeny tiny component system :mag:

Usage

var PicoComponent = require('picocomponent')

function Button () {
  PicoComponent.call(this)
  this.el = document.createElement('button')
}

Button.prototype = Object.create(PicoComponent.prototype)

Button.prototype.render = function render (text) {
  this.el.innerText = text
  return this.el
}

var button = new Button()

document.body.appendChild(button.render('Hello world!'))

API

PicoComponent.prototype

PicoComponent aims to provide a Class like interface for constructing components.

As a consumer you'll always want to extend the PicoComponent.prototype either via ES6 classes:

class Component extends PicoComponent {
  // ...
}

or by extending the base prototype:

function Component () {
  PicoComponent.call(this)
}

Button.prototype = Object.create(PicoComponent.prototype)

Instances of PicoComponent have the following internal properties:

  • this.el: Used to manage the DOM node a component is responsible for. Defaults to null. See How do I manage DOM nodes for more info.

PicoComponent.prototype.render(...args)

You'll always want to implement a render function. This forms the public interface for your component, and will generally leverage some templating library to manage rendering and updating your component. Your render method should always return DOM nodes.

PicoComponent.prototype.connect()

When assigned, the connect handler will be called once your component has been inserted into the DOM.

PicoComponent.prototype.disconnect()

When assigned, the disconnect handler will be called once your component has been removed from the DOM.

FAQ

Is this a joke?

It may seem that way, but seriously this exists as a result of other component systems eg. nanocomponent being focused on producing components targeted at DOM morphing libraries such as nanomorph and morphdom.

For this reason picocomponent aims to be more general purpose, leaving DOM diffing strategies up to the consumer, while still providing useful features such as connect/disconnect event listeners by integrating on-load.

How do I manage DOM nodes

As a matter of convention PicoComponent implements a custom getter/setter used for managing the DOM node your component is responsible for.

When assigning a DOM node to your PicoComponent instance eg:

class Button extends PicoComponent {
  constructor () {
    super()
    this.el = document.createElement('button')
  }
}

PicoComponent will ensure all appropriate lifecycle hooks are correctly assigned.

Have you gone too far?

Eh.

See also:

License

MIT