suiweb
Type Aliases
CreateElementFunction
Ƭ CreateElementFunction<T
>: (type
: keyof HTMLElementTagNameMap
| (props?
: Record
<string
, unknown
>) => T
, props
: Props
| null
, ...children
: (T
| Primitive
)[]) => T
Type parameters
Name | Type |
---|---|
T | Fiber |
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
Name | Type | Description |
---|---|---|
type | keyof HTMLElementTagNameMap | (props? : Record <string , unknown >) => T | The type can either be a HTML tag or a function, which returns an element. |
props | Props | null | The 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
Ƭ Fiber: StaticFiber
| FunctionalFiber
A Fiber
can be either a StaticFiber or a FunctionalFiber.
Defined in
FiberFunction
Ƭ FiberFunction: (props?
: Props
) => Fiber
Type declaration
▸ (props?
): Fiber
The FiberFunction
of a FunctionalFiber, which returns a Fiber.
Parameters
Name | Type |
---|---|
props? | Props |
Returns
Defined in
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
Primitive
Ƭ Primitive: string
| number
| bigint
| boolean
| symbol
| null
| undefined
Defined in
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
SjdonElement
Ƭ SjdonElement: [SjdonElementType
, ...(SjdonElementOrPrimitive | Props)[]]
A SjdonElement
is an array containing at least one element.
The first element is of type SjdonElementType and specifies the type of the SjdonElement
.
The other elements are either children or props of the element.
Chidren can be either a complete SjdonElement
or a Primitive.
Props are always an object of type Props.
Example
// a heading 1 with no content
const minimalElement: SjdonElement = ['h1']
// a div containing a text and a paragraph
const elementWithChildren: SjdonElement = ['div', 'Test', ['p', 'Hello World!']]
// a button with specified onclick props and a text child.
const elementWithProps: SjdonElement = [
'button',
{ onclick: () => console.log('Button clicked!') },
'Click me!'
]
Defined in
SjdonElementFunction
Ƭ SjdonElementFunction<T
>: (props?
: T
& { children?
: SjdonElementOrPrimitive
[] }) => SjdonElement
Type parameters
Name | Type |
---|---|
T | Record <string , unknown > |
Type declaration
▸ (props?
): SjdonElement
A SjdonElementFunction
takes in props as a parameter and returns a SjdonElement.
Parameters
Name | Type | Description |
---|---|---|
props? | T & { children? : SjdonElementOrPrimitive [] } | The props of the element. Children are automatically passed via the reserved children property. |
Returns
Defined in
SjdonElementOrPrimitive
Ƭ SjdonElementOrPrimitive: SjdonElement
| Primitive
A SjdonElementOrPrimitive
is either a SjdonElement or a Primitive.
Defined in
SjdonElementType
Ƭ SjdonElementType: keyof HTMLElementTagNameMap
| SjdonElementFunction
The type of a SjdonElement, which is specified in the first element of the array. It can either be a HTML tag or a SjdonElementFunction.
Defined in
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
Name | Type | Description |
---|---|---|
children | Map <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 | Text | The reference to the DOM node which this fiber represents. Is only set when the fiber is rendered. |
props | Readonly <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 |
type | StaticFiberType | The type of the static fiber. It is either a html tag or a custom tag for text or placeholder nodes. |
Defined in
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
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
Functions
createElement
▸ createElement(type
, props
, ...children
): Fiber
The SuiWeb implementation of the generic CreateElementFunction, which creates a Fiber.
Parameters
Name | Type | Description |
---|---|---|
type | keyof HTMLElementTagNameMap | (props? : Record <string , unknown >) => Fiber | If the type is a HTML tag, a StaticFiber is created. If it's a function, a FunctionalFiber is created. |
props | null | Props | The props of the element. |
...children | (Primitive | Fiber )[] | The children of the element. |
Returns
The created Fiber, either a StaticFiber or a FunctionalFiber.
Defined in
parseSjdon
▸ parseSjdon<T
>(param0
, create
): T
Parses a SjdonElement with all its children and creates a fiber tree. Uses the createElement function to create all fibers.
Type parameters
Name |
---|
T |
Parameters
Name | Type | Description |
---|---|---|
param0 | SjdonElement | The SjdonElement which should be parsed. |
create | CreateElementFunction <T > | The function which is used to create the elements. It works properly with the SuiWeb implementation createElement, but also other implementations, like React.createElement , could be used. Note, however, that this is only partially supported, as the typing don't match and the props are not fully compatible. |
Returns
T
The root element of the tree containing all children.
Defined in
render
▸ render(fiber
, container
): void
Renders the given fiber and its children to the DOM in the given container. Note that all children of the container will be removed from the DOM, before the fiber and its children are rendered.
Parameters
Name | Type | Description |
---|---|---|
fiber | Fiber | The fiber which should be rendered. |
container | HTMLElement | The container in which the fiber should be rendered. |
Returns
void
Defined in
useEffect
▸ useEffect(action
, dependencies?
): void
The function useEffect
can be used in a functional component to execute an action,
after a component has been rendered. By specifying dependencies
, calling the function
can be further restricted, to only call action
under specific contidtions.
Example
const Counter = () => {
const [count, setCount] = useState(0)
// `action` is called after every render.
useEffect(() => console.log('Counter changed.')) // no dependencies defined
// `action` is called after every render, if the value of `count`
// changed since the last render.
useEffect(() => console.log('Counter changed.'), [count]) // specific dependency defined
// `action` is called only after the first render.
useEffect(() => console.log('Counter changed.'), []) // empty array dependency
return <button onClick={() => setCount(count + 1)}>{`Count: ${count}`}</button>
}
Parameters
Name | Type | Description |
---|---|---|
action | () => void | The action to execute after rendering the component. |
dependencies? | unknown [] | Defines the dependencies that decide on execution of action . action will only be called if any of the value in the dependencies has changed since the last render of the component. Pass an empty array ([] ) to only run action on the first render. Pass undefined (or leave away the parameter) to run action on every render. |
Returns
void
Defined in
useState
▸ useState<T
>(initialValue
): [T
, (newValue
: T
) => void
]
The function useState
can be used inside a functional component to capture
state between re-rerenders. State values should never be mutated directly,
but always updated via the returned setState
function (2nd element in the array).
This will trigger a re-render of the FunctionalFiber
and its subtree (children).
Example
const Counter = () => {
const [count, setCount] = useState(0)
return <button onClick={() => setCount(count + 1)}>{`Count: ${count}`}</button>
}
Type parameters
Name |
---|
T |
Parameters
Name | Type | Description |
---|---|---|
initialValue | T | The initial value the state should have. |
Returns
[T
, (newValue
: T
) => void
]
An array containing the state
as the first element and
the setState
function as the second element.