Skip to content

ReactiveState

Inherits: ReactiveSubject

Methods

GetDefaultValue

lua
function ReactiveState:GetDefaultValue(key)
  -> any

Gets the default value of a state field.

Parameters:

NameTypeDescription
keystringThe key to get the default value of

Returns:

TypeDescription
any

Publisher

lua
function ReactiveState:Publisher(expressionStr)
  -> ReactivePublisherSchema

Creates a publisher for an expression which operates on state fields.

Parameters:

NameTypeDescription
expressionStrexpression<self & ReactiveExprBuiltins, R>A valid lua expression which can only access fields of the state (as globals)

Returns:

TypeDescription
ReactivePublisherSchema

PublisherForFunctionWithKeys

lua
function ReactiveState:PublisherForFunctionWithKeys(func, ...)
  -> ReactivePublisherSchema

Creates a new publisher which publishes the state when the result of a function which gets passed the specified keys changes. NOTE: The function must be constant and strictly depend on its inputs only.

Parameters:

NameTypeDescription
funcfun(...: any, ...): anyThe function which gets the values of the specified keys and returns the value to publish (if it changes)
...stringThe keys to pass to the function

Returns:

TypeDescription
ReactivePublisherSchema

PublisherForKeys

lua
function ReactiveState:PublisherForKeys(...)
  -> ReactivePublisherSchema

Creates a new publisher which publishes the state when any of the specified keys change.

Parameters:

NameTypeDescription
...stringThe keys to create a publisher for

Returns:

TypeDescription
ReactivePublisherSchema

ResetToDefault

lua
function ReactiveState:ResetToDefault()

Resets the state to its default value.

SetAutoDeferred

lua
function ReactiveState:SetAutoDeferred(deferred)

Sets whether or not new publishers which are added should be deferred and handled as late as possible.

Parameters:

NameTypeDescription
deferredbooleanWhether or not to defer publishers

SetAutoDisable

lua
function ReactiveState:SetAutoDisable(disable)
  -> self

Sets whether or not new publishers are automatically disabled when stored.

Parameters:

NameTypeDescription
disablebooleanDisable publishers when stored

Returns:

TypeDescription
self

SetAutoStore

lua
function ReactiveState:SetAutoStore(tbl)
  -> self

Automatically stores any new publishers in the specified table.

Parameters:

NameTypeDescription
tbltableThe table to store new publishers in

Returns:

TypeDescription
self

SetAutoStorePaused

lua
function ReactiveState:SetAutoStorePaused(paused)

Sets whether automatic storing of new publisher is paused.

Parameters:

NameTypeDescription
pausedbooleanPause or unpause automatic storing of publishers

WithAutoStorePaused

lua
function ReactiveState:WithAutoStorePaused()
  -> function, any, any

Returns an iterator which executes exactly once with auto store paused within the loop body.

Returns:

TypeDescription
function
any
any