0.6.2 • Published 9 years ago

react-vdom v0.6.2

Weekly downloads
2
License
MIT
Repository
github
Last release
9 years ago

build status dependency status npm downloads

Important

If you are using React v0.13 you may want to install react-vdom v0.5.

The Idea

I wrote this handy little library for testing purposes: you can extract the vdom from a React component and test it against a JSON with simple tools like assert.deepEqual() and without a real DOM. The extracted vdom has the following type definition:

type Node = {
  tag: string,
  attrs: object<name, value>,
  children: undefined | null | Node | Array<Node>
}

If your component handle a private state, you can inject a state to test different configurations.

Basic example

var vdom = require('react-vdom');

// a simple component
var Counter = React.createClass({
  getInitialState: function () {
    return {count: 0};
  },
  render: function () {
    return (
      React.DOM.div(null, this.state.count)
    );
  }
});

var json = vdom(<Counter />);
console.log(json);

outputs

{
  "tag": "div",
  "attrs": {},
  "children": 0
}

Inject a state

var state = {count: 1};
console.log(vdom(<Counter />, state));

outputs

{
  "tag": "div",
  "attrs": {},
  "children": 1
}

Setup

npm install react-vdom

Api

vdom(element, [state])
  • element a ReactElement
  • state inject a state

Returns a JSON containing a synthetic VDOM.

License (MIT)

0.6.2

9 years ago

0.6.1

9 years ago

0.6.0

9 years ago

0.5.0

9 years ago

0.4.0

9 years ago

0.3.0

10 years ago

0.2.4

10 years ago

0.2.3

10 years ago

0.2.2

10 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.1

10 years ago