Skip to main content

Interface: StateConfigWrapper<K, V>

@lexical/utils.StateConfigWrapper

A wrapper that creates bound functions and methods for the StateConfig to save some boilerplate when defining methods or exporting only the accessors from your modules rather than exposing the StateConfig directly.

Type parameters

NameType
Kextends string
VV

Properties

$get

Readonly $get: <T>(node: T) => V

(node) => $getState(node, stateConfig)

Type declaration

▸ <T>(node): V

Type parameters
NameType
Textends LexicalNode
Parameters
NameType
nodeT
Returns

V

Defined in

packages/lexical-utils/src/index.ts:878


$set

Readonly $set: <T>(node: T, valueOrUpdater: ValueOrUpdater<V>) => T

(node, valueOrUpdater) => $setState(node, stateConfig, valueOrUpdater)

Type declaration

▸ <T>(node, valueOrUpdater): T

Type parameters
NameType
Textends LexicalNode
Parameters
NameType
nodeT
valueOrUpdaterValueOrUpdater<V>
Returns

T

Defined in

packages/lexical-utils/src/index.ts:880


accessors

Readonly accessors: readonly [<T>(node: T) => V, <T>(node: T, valueOrUpdater: ValueOrUpdater<V>) => T]

[$get, $set]

Defined in

packages/lexical-utils/src/index.ts:885


stateConfig

Readonly stateConfig: StateConfig<K, V>

A reference to the stateConfig

Defined in

packages/lexical-utils/src/index.ts:876

Methods

makeGetterMethod

makeGetterMethod<T>(): (this: T) => V

() => function () { return $get(this) }

Should be called with an explicit this type parameter.

Type parameters

NameType
Textends LexicalNode

Returns

fn

▸ (this): V

Parameters
NameType
thisT
Returns

V

Example

class MyNode {
// …
myGetter = myWrapper.makeGetterMethod<this>();
}

Defined in

packages/lexical-utils/src/index.ts:899


makeSetterMethod

makeSetterMethod<T>(): (this: T, valueOrUpdater: ValueOrUpdater<V>) => T

() => function (valueOrUpdater) { return $set(this, valueOrUpdater) }

Must be called with an explicit this type parameter.

Type parameters

NameType
Textends LexicalNode

Returns

fn

▸ (this, valueOrUpdater): T

Parameters
NameType
thisT
valueOrUpdaterValueOrUpdater<V>
Returns

T

Example

class MyNode {
// …
mySetter = myWrapper.makeSetterMethod<this>();
}

Defined in

packages/lexical-utils/src/index.ts:913