Skip to main content

Module: fiber

Type Aliases

CreateElementFunction

Ƭ CreateElementFunction<T>: (type: keyof HTMLElementTagNameMap | (props?: Record<string, unknown>) => T, props: Props | null, ...children: (T | Primitive)[]) => T

Type parameters

NameType
TFiber

Type declaration

▸ (type, props, ...children): T

A function which creates elements from a type, props and children. Can be used with SJDON, but also standards like JSX. It is in the same format as the React.createElement function so it could possibly be interchanged. But note that the typings don't match exactly, e.g., React.createElement can't handle all values of Props.

Parameters
NameTypeDescription
typekeyof HTMLElementTagNameMap | (props?: Record<string, unknown>) => TThe type can either be a HTML tag or a function, which returns an element.
propsProps | nullThe props of the element. If JSX is used instead of SJDON, it has to be made sure that the "special props" like style or key overlap enough with the Props. This should be the case for the properties style and key, but is not guaranteed for all props. To provide basic functionality, also JSX on<Event> event handlers are supported.
...children(T | Primitive)[]The children of the element.
Returns

T

The generated element.

Defined in

fiber.ts:171


Fiber

Ƭ Fiber: StaticFiber | FunctionalFiber

A Fiber can be either a StaticFiber or a FunctionalFiber.

Defined in

fiber.ts:6


FiberFunction

Ƭ FiberFunction: (props?: Props) => Fiber

Type declaration

▸ (props?): Fiber

The FiberFunction of a FunctionalFiber, which returns a Fiber.

Parameters
NameType
props?Props
Returns

Fiber

Defined in

fiber.ts:97


FunctionalFiber

Ƭ FunctionalFiber: { fiberFunction: FiberFunction ; functionProps: Readonly<Props> ; memorizedStates: unknown[] } & Partial<StaticFiber>

A FunctionalFiber represents an element, which is generated by a function call. This generator-function is stored in the property fiberFunction and when the component is re-rendered, the fiberFunction is called with functionalProps as argument. In the fiberFunction, hooks can be called, whose values are stored in the memorizedStates array.

StaticFiber Properties

A FunctionalFiber contains all properties of a StaticFiber, but only as optionals. The properties type, props and children, which define a StaticFiber, are only assigned when the component is unwrapped i.e., its fiberFunction is called. This happens during rendering, when the fiberFunction is called. The returned StaticFiber will be merged into the FunctionalFiber and provide these three properties.

Defined in

fiber.ts:73


Props

Ƭ Props: { children?: never ; key?: string | number | null ; style?: StyleProp } & Partial<Omit<HTMLElement, "style" | "children">> & Record<string, unknown>

The Props which a SuiWeb Fiber expects.

Defined in

fiber.ts:117


StaticFiber

Ƭ StaticFiber: Object

A StaticFiber represents a static element in the DOM. It does not contain a function and thus can't use hooks, so it will never trigger a re-render. It is completely defined by its type, props and children. Its domNode will be assigned when it is rendered to the DOM.

Type declaration

NameTypeDescription
childrenMap<string, Fiber>The children of the fiber are stored in a map where every child has a unique key. If no key is provided in the props of the corresponding child, a default key is used.
domNode?HTMLElement | TextThe reference to the DOM node which this fiber represents. Is only set when the fiber is rendered.
propsReadonly<Props>The props of the static fiber. These will be added to them DOM node when it is rendered. There are special props like key which serve their custom purpose and are not added to the DOM node. See isNormalProp
typeStaticFiberTypeThe type of the static fiber. It is either a html tag or a custom tag for text or placeholder nodes.

Defined in

fiber.ts:14


StaticFiberType

Ƭ StaticFiberType: keyof HTMLElementTagNameMap | "TEXT_NODE" | "PLACEHOLDER_NODE"

The possible type of a StaticFiber. Fibers with type TEXT_NODE or PLACEHOLDER_NODE will not be rendered to the dom directly, but are treated specially instead.

Defined in

fiber.ts:43


StyleProp

Ƭ StyleProp: string | Partial<CSSStyleDeclaration> | Partial<CSSStyleDeclaration>[]

The StyleProp is usally passed as the style property of the props. It can either be:

  • a CSS string which is set directly to style attribute.
  • an object containing CSS properties in camelCase.
  • an array of objects containing CSS properties in camcelCase.

Defined in

fiber.ts:144

Functions

createElement

createElement(type, props, ...children): Fiber

The SuiWeb implementation of the generic CreateElementFunction, which creates a Fiber.

Parameters

NameTypeDescription
typekeyof HTMLElementTagNameMap | (props?: Record<string, unknown>) => FiberIf the type is a HTML tag, a StaticFiber is created. If it's a function, a FunctionalFiber is created.
propsnull | PropsThe props of the element.
...children(Primitive | Fiber)[]The children of the element.

Returns

Fiber

The created Fiber, either a StaticFiber or a FunctionalFiber.

Defined in

fiber.ts:171


isFunctionalFiber

isFunctionalFiber(object): object is FunctionalFiber

Determines if an object is of type FunctionalFiber.

Parameters

NameTypeDescription
objectunknownThe object to check.

Returns

object is FunctionalFiber

true if the object is of type FunctionalFiber.

Defined in

fiber.ts:104


isNormalProp

isNormalProp(propName): boolean

Determines if the given propName is a normal prop which should be directly added to the DOM node, or if it serves a custom purpose. Currently there are three special props, namely children, style and key.

Parameters

NameTypeDescription
propNamestringThe name of the prop to check.

Returns

boolean

true if the given prop is a normal prop.

Defined in

fiber.ts:153


isStaticFiber

isStaticFiber(object): object is StaticFiber

Determines if an object is of type StaticFiber.

Parameters

NameTypeDescription
objectunknownThe object to check.

Returns

object is StaticFiber

true if the object is of type StaticFiber.

Defined in

fiber.ts:50