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 🙏

© 2025 – Pkg Stats / Ryan Hefner

virtual-component

v0.2.5

Published

Components for virtual-dom

Readme

virtual-component

js-standard-style

Components for virtual-dom

Installation

$ npm install virtual-component

Usage

virtual-component enables you to write react/deku style components in your virtual-dom application. E.g.

import {fetch} from 'redux-effects-fetch'

function beforeMount (props) {
  return actions.fetchStories(props.categoryId)
}

function render (props) {
  return (
    <div>
      {
        props.children.map(story => <Story story={story} />)
      }
    </div>
  )
}

export default {
  beforeMount,
  render
}

Hooks

It supports the following hooks:

  • beforeMount(props) - Before the initial DOM element is created
  • beforeUpdate(prevProps, nextProps) - Before a state update (not called on initial render)
  • afterUpdate(prevProps, nextProps) - After a state update (not called on initial render).
  • afterMount(props) - After the initial DOM element is rendered
  • beforeUnmount(props) - Before the DOM element is removed
  • transformProps(props) - Transforms props before they are passed to any of the above. Takes props as an argument, returns a new props object.

Each of these hooks takes either a single argument props or prevProps and nextProps. And it may return a single-value, an action (or array of actions, if using redux-multi, which can be listened to at the top-level of your application, like this:

import {listen} from 'virtual-component'
import store from 'my-redux-store'

listen(store.dispatch)

shouldUpdate

By default your component assumes that your props are immutable, and will only update when there is a shallow change in your props object. If you want to change this behavior, your component may export a shouldUpdate function:

function shouldUpdate (nextProps, prevProps) {
  return nextProps.someKey !== prevProps.someKey
}

function render (props) {
  // ...Etc
}

export default {
  render,
  shouldUpdate
}

children

The props object passed to your component has a single special property: children. It consists of the child nodes (if any) of your component. E.g.

function List (props) {
  return (
    <ul>
      {
        props.children.map(item => <li>{item}</li>)
      }
    </ul>
  )
}

function PrimaryColors (props) {
  return (
    <List>
      <span>red</span>
      <span>green</span>
      <span>blue</span>
    </List>
  )
}

Single function component

If you don't want to use any hooks and you don't want to use shouldUpdate, as most of your components should, then you may just export a single function: render, with no object wrapper. E.g.

export default function render (props) {
  // Render some stuff
}

This works particularly well with a redux store, and vdux bridge between virtual-dom and redux.

Using redux-effects, you can also keep all side-effects out of your hooks and only return pure values, but that is optional.

Notes

  • The window.dispatchEvent stuff is a temporary hack until I think of a better way of doing that.

If you have any suggestions for either of these, please let me know.

License

The MIT License

Copyright © 2015, Weo.io <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.