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

hyperd

v0.1.0

Published

Virtual DOM based, template engine agnostic, a lightweight view library

Downloads

20

Readme

Hyperd

Build Status

Virtual DOM based, template engine agnostic, a lightweight view library.

var component = hyperd(document.getElementById('count'), function() {
  return '<div id="count">Counter: ' + this.data.count + '</div>';
});

component.data.count = 0;

setInterval(function() {
  component.data.count++;
}, 1000);

Installation

$ npm install hyperd
<script src="node_modules/hyperd/hyperd.js"></script>

With Bower

$ bower install hyperd

Features

  • Virtual DOM diffing
  • Template engine agnostic
  • Auto-redrawing
  • Building reusable components
  • Small API

Examples

API Documentation

hyperd(node, render)

  • node HTMLElement Node to attach
  • render Function Called upon redrawing, should return a html string.
  • Return: hyperd.Component

A short circuit to create a simple component instance.

Class: hyperd.Component

The base component class.

Class Method: hyperd.Component.extend(proto);

  • proto Object protoype object
  • Return: Function A new component constructor

Creates a new component class.

var MyComponent = hyperd.Component.extend({
  render: function() {
    return '<div>hi</div>';
  }
});

new hyperd.Component([props])

  • props Object properties

In classes that extends hyperd.Component, make sure to call the super constructor so that the all settings can be initialized.

hyperd.Component.extend({
  constructor: function(props) {
    hyperd.Component.apply(this, arguments);
    ...
  }
});

component.props

The properties of the component.

var component = new MyComponent({ foo: "hi" });
console.log(component.props.foo); // "hi"

component.data

The state data of the component. Mutating data triggers UI updates.

component.node

The node element which the component is attached to.

component.components

Definitions of child components. You can use defined components like a custom element on render().

var Child = hyperd.Component.extend({
  render: function() {
    return '<div>' + this.props.foo + '</div>';
  }
});

hyperd.Component.extend({
  components: { child: Child },
  render: function() {
    return  '<div><child foo="hi"></div>'
  }
});

component.attachTo(node)

  • node HTMLElement
  • Return: this

Attaches the component to a DOM node.

component.render()

  • Return: String A html string to render.

Note: implement this function, but do NOT call it directly.

Reuired to implement. This method is called automatically and asynchronously when you update component.data.

component.destroy()

Teardown and delete all properties and event bindings including descendant components.

component.emit(event[, args1][, args2][, ...])

  • event String The event type to be triggered.
  • Return: this

Trigger a DOM event for component.node with the supplied arguments.

component.emit('edit', arg);

component.on(event, listener)

  • event String The event type.
  • listener Function
  • Return: this

Add a listener for the specified event.

component.on('render', function() { ... });

component.on(event, selector, listener)

  • event String The event type.
  • selector String CSS selector.
  • listener Function The listener always take an event object as the first argument.
  • Return: this

Add a listener for the delegated event. The listener is called only for descendants that match the selector. You can use this to listen an event of a child component too.

hyperd.Component.extend({
  constructor: function() {
    hyperd.Component.apply(this, arguments);
    this.on('click', 'button', function(event) {
      console.log('clicked!');
    });
  }
  render: function() {
    return  '<div><button type="button">Click me!</button></div>'
  }
});

component.removeListener(event, listener)

Remove a listener for the specified event.

component.removeListener(event, selector, listener)

Remove a listener for the delegated event.

component.removeAllListeners([event][, selector])

Remove all listeners, or those of the specified event or the delegated event.

component.onAttach()

Called upon after the component is attached to a node.

component.onRender()

Called upon after the component is rerendered.

component.onDestroy()

Called upon after the component is destroyed.

Event: 'attach'

The same as component.onAttach.

component.on('attach', function() { ... });

Event: 'render'

The same as component.onRender.

Event: 'destroy'

The same as component.onDestroy.

Attribute: 'data-hkey'

The identifier used to differentiate a node. Used to reconcile an element will be reordered or destroyed.

hyperd.Component.extend({
  render: function() {
    var items = ['foo', 'bar', 'baz'];
    return '<ul>' + items.map(function(item) {
      return '<li data-hkey="' + item + '">' + item + '</li>';
    }) + '</ul>';
  }
});

Licence

MIT