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

@nathanfaucett/virt-dom

v0.0.16

Published

virt DOM is a render adapter for virt

Downloads

10

Readme

virt DOM Build Status

virt DOM is a render adapter for the virt library, virt was created after reading facebook's React source code. The main difference is virt creates changes as JSON that an adapter like virt-dom uses to render to some view system, in this case the DOM.

Install using NPM

$ npm install @nathanfaucett/virt-dom --save

API

addNativeComponent(type: String, constructor: Function)

Adds a new native component to virt-dom. Used by virt-dom to implement native elements like img, button, etc... needs to be called before rendering.

addNativeHandler(type: String, fn: Function)

Adds a new native handler component to virt-dom. Used by virt-dom to implement native messages accross the messenger api.

render(view: View, containerDOMNode: DOMElement, [, callback: Function])

Renders the view to the dom element and calls the callback when it is done.

unmount(containerDOMNode: DOMElement)

Removes all data associated with the parent element given and removes it from the DOM.

renderString(view: View[, id: String]) -> String

Render view to string using the id given as the root id of the DOM elements, defaults to 0.

findDOMNode(value: View|String) -> DOMElement

Returns the DOMElement associated with the view or id givent by value.

findRoot(value: String) -> virt.Root

Returns the virt.Root associated with the id

findEventHandler(value: String) -> virt.EventHandler

Returns the virt.EventHandler associated with the id

createWorkerRender(url: String, containerDOMNode: DOMElement) -> Messenger

Returns the Messenger created to communicate with the workers view component. used on the client side

renderWorker(view: View[, callback: Function])

Creates a diff from the view and the last view, then sends it over the messenager api to the client created with virtDOM.createWorkerRender. Used on the server side.

createWebSocketRender(containerDOMNode: DOMElement, socket: WebSocket[, attachMessage: Function], [sendMessage: Function]) -> Messenger

Returns the Messenger created to communicate over the web socket to the view side. used on the client side

renderWebSocket(view: View, socket: WebSocket[, attachMessage: Function][, sendMessage: Function] [, callback: Function])

Creates a diff from the view and the last view, then sends it over the messenager api to the client created with virtDOM.createWebSocketRender. Used on the server side.

Examples

Full site example here http://bomontfii.com, Some technical examples can be found here

###Usage

The best way to use virt is to create custom components that inherit from the virt.Component class.

var virt = require("virt"),
    virtDOM = require("virt-dom");


function List(props, children, context) {
    virt.Component.call(this, props, children, context);

    this.state = {
        items: [
            {id: 0, text: "Item 1"},
            {id: 1, text: "Item 2"}
        ]
    };
}
// same as
// List.prototype = Object.create(virt.Component.prototype);
// List.prototype.displayName = "List";
virt.Component.extend(List, "List");

List.prototype.onClick = function(id) {
    var _this = this;

    this.state.items.forEach(function(value, index, array) {
        if (value.id === id) {
            array.splice(index, 1);
            _this.setState({
                items: array
            });
            return false;
        }
    });
};

List.prototype.render = function() {
    var _this = this;

    return (
        virt.createView("ul", this.state.items.map(function(item) {
            return virt.createView(Item, {
                key: item.id,
                onClick: function onClick() {
                    _this.onClick(item.id);
                },
                text: item.text
            });
        }));
    );
};

function Item(props, children, context) {
    virt.Component.call(this, props, children, context);
}
virt.Component.extend(Item, "Item");

Item.prototype.render = function() {
    return (
        virt.createView("li", {
            onClick: this.props.onClick
        }, this.props.text);
    );
};

virtDOM.render(virt.createView(List), document.getElementById("app"));