inferno-vnode-flags
v10.0.0
Published
Provides an enum of all possible VNode Flags used when calling Inferno.createVNode
Readme
inferno-vnode-flags
Inferno VNode Flags is a small utility library for Inferno.
Usage of inferno-vnode-flags should be limited to assigning VNodeFlags and ChildFlags when using creating vNodes.
Install
npm install --save inferno-vnode-flagsContents
VNodeFlags:
The JSX plugins write the flags into the compiled code as one number, so the flags that compiled apps and Inferno use most have the smallest values. The values changed in Inferno 10, so compile JSX with the v10 plugins.
VNodeFlags.HtmlElement(1)VNodeFlags.SvgElement(64)VNodeFlags.ComponentClass(128)VNodeFlags.Fragment(256)VNodeFlags.InputElement(512)VNodeFlags.Text(1024)VNodeFlags.TextareaElement(2048)VNodeFlags.SelectElement(4096)VNodeFlags.ComponentFunction(8192)VNodeFlags.Portal(16384)VnodeFlags.ForwardRef(32768)VNodeFlags.InUse(65536)VNodeFlags.ContentEditable(131072)VNodeFlags.Validated(262144) development only, the keys of the vNode's children have been validatedVNodeFlags.Normalized(524288)VNodeFlags.ComponentUnknown(0)newComponentVNodefinds out whether the type is a class, a function or a forwardRef
ChildFlags in VNodeFlags:
A vNode keeps the shape of its children in bits of flags. Exactly one of these bits is set, test it with vNode.flags & VNodeFlags.HasKeyedChildren. newVNode, newComponentVNode and newFragment from inferno take the bit in their flags, for example VNodeFlags.HtmlElement | VNodeFlags.HasKeyedChildren; flags without a child bit make them normalize the children. The deprecated createVNode and createFragment take a separate ChildFlags value, which has the same name as its bit but another value. getChildFlags(vNode) from inferno converts the bits back to a ChildFlags value, for passing them to those.
VNodeFlags.HasTextChildren(2)VNodeFlags.HasNonKeyedChildren(4)VNodeFlags.HasVNodeChildren(8)VNodeFlags.HasInvalidChildren(16)VNodeFlags.HasKeyedChildren(32)VNodeFlags.MultipleChildren- Mask of the keyed and non-keyed bitsVNodeFlags.ChildFlagsMask- Bits that hold the shape of the children
VNodeFlags Masks:
VNodeFlags.ForwardRefComponentFunctional component wrapped in forward refVNodeFlags.FormElement- Is form elementVNodeFlags.Element- Is vNode elementVNodeFlags.Component- Is vNode ComponentVNodeFlags.DOMRef- Bit set when vNode holds DOM referenceVNodeFlags.InUseOrNormalized- VNode is used somewhere else or came from normalization processVNodeFlags.ClearInUseNormalized- Opposite mask of InUse or NormalizedVNodeFlags.IgnoredByPatch- Bits that don't make two vNodes different types: Normalized, ChildFlags and ValidatedVNodeFlags.ClearOnCopy- Clears the ChildFlags, Validated, InUse and Normalized bits of flags copied from another vNode, before a new child bit is added
ChildFlags
ChildFlags.UnknownChildrenneeds NormalizationChildFlags.HasInvalidChildrenis invalid (null, undefined, false, true)ChildFlags.HasVNodeChildren(JSX $HasVNodeChildren) is single vNode (Element/Component)ChildFlags.HasNonKeyedChildren(JSX $HasNonKeyedChildren) is Array of vNodes non keyed (no nesting, no holes)ChildFlags.HasKeyedChildren(JSX $HasKeyedChildren) is Array of vNodes keyed (no nesting, no holes)ChildFlags.HasTextChildren(JSX $HasTextChildren) vNode contains only text
ChildFlags Masks
ChildFlags.MultipleChildrenIs Array
You can easily combine multiple flags, by using bitwise operators. A common use case is an element that has keyed children:
import { newVNode } from 'inferno';
import { VNodeFlags } from 'inferno-vnode-flags';
const list = newVNode(
VNodeFlags.HtmlElement | VNodeFlags.HasKeyedChildren,
'ul',
null,
items, // vNodes with keys
);