Skip to main content

Reactor, Top-Level API

Creating Reactor Elements

JSX()

JSX(type,[props],[...children]): VNode

Constructs virtual node.

These two expressions are equivalent:

  const vn = <div id="foo">bar</div>;

is

  const vn = JSX("div", {id="foo"}, ["bar"]);

Reactor.cloneOf()

Reactor.cloneOf(velement,[props],[...children]): VNode

Clone and return a new Reactor virtual element using velement as the prototype.

props and children are optional.

If props is defined then the resulting element will have the original element’s props with the new props merged in shallowly. New children will replace existing children. key prop from the original element will be preserved.

If children array is defined it will replace children of original element.

Inspection of virtual DOM

Reactor.isNode()

Reactor.isNode(object): boolean

Returns true if the object is JSX literal or was constructed by either JSX function or Reactor.cloneOf

Reactor.tagOf()

Reactor.tagOf(vnode)

Returns tag of virtual node.

   Reactor.tagOf(<div/>) == "div"; // true

Reactor.propsOf()

Reactor.propsOf(vnode) : Object

Returns properties (attributes) of virtual node as an object.

   Reactor.propsOf(<div id="foo" />).id == "foo"; // true

Reactor.kidsOf()

Reactor.kidsOf(vnode) : Array

Returns children collection of virtual node as an array.

   Reactor.kidsOf(<div>bar</div>)[0] == "bar"; // true