@elemental/common / Function

createState

Generic types:T

Create a state object with signals, computed signals and effects. All the signals into withSignals are converted to writable signals.

Presentation

function createState(withSignals: T): {
  [K in keyof T]: WritableSignal<ExtractSignal<T[K]>>;
};

Returns

{ [K in keyof T]: WritableSignal<ExtractSignal<T[K]>>; }

Parameters

NameTypeDescription
withSignals
T

@param withSignals The signals to be used as state

Overloads

Overload #1

Create a state object with signals, computed signals and effects. All the signals into withSignals are converted to writable signals.

Presentation
createState(withSignals: T): { [K in keyof T]: WritableSignal<ExtractSignal<T[K]>>; };
Parameters
NameTypeDescription
withSignals
T

@param withSignals The signals to be used as state

Returns
{ [K in keyof T]: WritableSignal<ExtractSignal<T[K]>>; }
Overload #2

Create a state object with signals, computed signals and effects. All the signals into withSignals are converted to writable signals.

Presentation
createState(withSignals: T, withComputed: F): { [K in keyof T]: WritableSignal<ExtractSignal<T[K]>>; } & { [B in keyof F]: Signal<ReturnType<F[B]>>; };
Parameters
NameTypeDescription
withSignals
T

@param withSignals The signals to be used as state

withComputed
F

@param withComputed The computed signals to be used as state based on the withSignals

Returns
{ [K in keyof T]: WritableSignal<ExtractSignal<T[K]>>; } & { [B in keyof F]: Signal<ReturnType<F[B]>>; }
Overload #3

Create a state object with signals, computed signals and effects. All the signals into withSignals are converted to writable signals.

Presentation
createState(withSignals: T, withComputed: F, withEffects: G): { [K in keyof T]: WritableSignal<ExtractSignal<T[K]>>; } & { [B in keyof F]: Signal<ReturnType<F[B]>>; } & { [J in keyof G]: EffectRef; };
Parameters
NameTypeDescription
withSignals
T

@param withSignals The signals to be used as state

withComputed
F

@param withComputed The computed signals to be used as state based on the withSignals

withEffects
G

@param withEffects The effects to be used as state based on the withSignals

Returns
{ [K in keyof T]: WritableSignal<ExtractSignal<T[K]>>; } & { [B in keyof F]: Signal<ReturnType<F[B]>>; } & { [J in keyof G]: EffectRef; }