Skip to content

ReactivePublisherSchema

The ReactivePublisherSchema class is used to define the data pipeline which handles observed values from ReactiveState or ReactiveStream objects. These data pipelines are compiled into Lua functions, so their execution is highly performant.

Stages

The data pipeline has two stages:

The first stage applies transformations and filters to published values. Transformations (e.g. :Map()) change the value passing to the next step. Filters (e.g. :Ignore*()) either allow the current value through or halt the pipeline. Any number of transformations and filters may be defined in any order.

The second stage handles the final value via :Call*() or :AssignToTableKey(). Exactly one of these must be called — it commits the schema and returns a ReactivePublisher object.

Share

The :Share() method designates that the value at that point in the pipeline should be saved and shared across multiple subsequent data pipelines. It returns a ReactivePublisherSchemaShared object, which allows continuing from the commit methods before being finalized via :EndShare().

lua
self._state:Publisher([[subAddEnabled and (mouseOver or hasFocus)]])
   :Share()
   :CallMethod(self._subIcon, "SetShown")
   :CallMethod(self._subBtn, "SetShown")
   :CallMethod(self._addIcon, "SetShown")
   :CallMethod(self._addBtn, "SetShown")
   :EndShare()

Flat Map

The :FlatMapCall*() methods allow transforming published values into a new publisher, where the first argument is a function that receives published values and returns a new publisher.

Memory Management

Publisher schema objects are acquired exclusively via methods on ReactiveState and ReactiveStream and are recycled internally when committed.

API

Inherits: Class

Methods

AssignToTableKey

lua
function ReactivePublisherSchemaBase:AssignToTableKey(tbl, key)
  -> self

Assigns published values to the specified key in the table.

Parameters:

NameTypeDescription
tbltableThe table to assign the published values into
keystringThe key to assign the published values at

Returns:

TypeDescription
self

CallFunction

lua
function ReactivePublisherSchemaBase:CallFunction(func, arg)
  -> self

Calls a function with the published values.

Parameters:

NameTypeDescription
funcfun(value: T, arg: A)The function to call with the published values
argAAn additional argument to pass to the function

Returns:

TypeDescription
self

CallMethod

lua
function ReactivePublisherSchemaBase:CallMethod(obj, method, arg)
  -> self

Calls a method with the published values.

Parameters:

NameTypeDescription
objObjThe object to call the method on
methodKThe name of the method to call with the published values
arganyAn additional argument to pass to the method

Returns:

TypeDescription
self

CoalesceNil

lua
function ReactivePublisherSchemaBase:CoalesceNil(value)
  -> self

Coalesces nil published values to a specific value.

Parameters:

NameTypeDescription
valueVThe value to map to

Returns:

TypeDescription
self

FlatMapCallFunction

lua
function ReactivePublisherSchemaBase:FlatMapCallFunction(map, func, arg)
  -> self

Maps published values to a new publisher which is owned by the current publisher and call a function with values it publishes.

Parameters:

NameTypeDescription
mapReactivePublisherFlatMapFunc<T>A function which takes a published value and returns a new publisher
funcfun(value: T, arg: A)The function to call with the published values
argAAn additional argument to pass to the function

Returns:

TypeDescription
self

FlatMapCallMethod

lua
function ReactivePublisherSchemaBase:FlatMapCallMethod(map, obj, method, arg)
  -> self

Maps published values to a new publisher which is owned by the current publisher and call a method with values it publishes.

Parameters:

NameTypeDescription
mapReactivePublisherFlatMapFunc<T>A function which takes a published value and returns a new publisher
objObjThe object to call the method on
methodKThe name of the method to call with the published values
arganyAn additional argument to pass to the method

Returns:

TypeDescription
self

IgnoreDuplicates

lua
function ReactivePublisherSchemaBase:IgnoreDuplicates(hashFunc)
  -> self

Ignores duplicate published values.

Parameters:

NameTypeDescription
hashFuncstringA method call (in the form "MyMethod()") to calculate the hash to check for equality

Returns:

TypeDescription
self

IgnoreDuplicatesWithKeys

lua
function ReactivePublisherSchemaBase:IgnoreDuplicatesWithKeys(...)
  -> self

Ignores duplicate published values by checking the specified keys.

Parameters:

NameTypeDescription
...KKeys to compare to detect duplicate published values

Returns:

TypeDescription
self

IgnoreIfEquals

lua
function ReactivePublisherSchemaBase:IgnoreIfEquals(value, key)
  -> self

Ignores published values which equal the specified value.

Parameters:

NameTypeDescription
valueVThe value to compare against
keyKThe key to access for filtering

Returns:

TypeDescription
self

IgnoreIfNotEquals

lua
function ReactivePublisherSchemaBase:IgnoreIfNotEquals(value, key)
  -> self

Ignores published values which don't equal the specified value.

Parameters:

NameTypeDescription
valueVThe value to compare against
keyKThe key to access for filtering

Returns:

TypeDescription
self

IgnoreNil

lua
function ReactivePublisherSchemaBase:IgnoreNil()
  -> self

Ignores published values if it's nil.

Returns:

TypeDescription
self

InvertBoolean

lua
function ReactivePublisherSchemaBase:InvertBoolean()
  -> self

Invert published boolean values.

Returns:

TypeDescription
self

IsShared

lua
function ReactivePublisherSchemaBase:IsShared()
  -> boolean

Returns whether or not this is a shared publisher.

Returns:

TypeDescription
boolean

Map

lua
function ReactivePublisherSchemaBase:Map(map, arg)
  -> self

Map published values to another value.

Parameters:

NameTypeDescription
mapfun(value: T, arg: A): any | string | number | table<T, R>Either a map function, table key (string or number) to index, method call (in the form "MyMethod()"), or lookup table
argAAn additional argument to pass to a map function

Returns:

TypeDescription
self

MapNonNil

lua
function ReactivePublisherSchemaBase:MapNonNil(map, arg)
  -> self

Map non-nil publishes values to another value.

Parameters:

NameTypeDescription
mapfun(value: T, arg: A): R | string | table<T, R>Either a map function, method call (in the form "MyMethod()"), or lookup table
argAAn additional argument to pass to the map function or method

Returns:

TypeDescription
self

Print

lua
function ReactivePublisherSchemaBase:Print(tag)
  -> self

Prints published values and passes them through for debugging purposes.

Parameters:

NameTypeDescription
tagstringAn optional tag to add to the prints

Returns:

TypeDescription
self

ReplaceBooleanWith

lua
function ReactivePublisherSchemaBase:ReplaceBooleanWith(trueValue, falseValue)
  -> self

Replaces published boolean values with the specified true / false values.

Parameters:

NameTypeDescription
trueValueV1The value to replace with to if true
falseValueV2The value to replace with to if false

Returns:

TypeDescription
self

ReplaceWith

lua
function ReactivePublisherSchemaBase:ReplaceWith(value)
  -> self

Replaces published values with the specific value.

Parameters:

NameTypeDescription
valueVThe value to replace with

Returns:

TypeDescription
self

ToBooleanEquals

lua
function ReactivePublisherSchemaBase:ToBooleanEquals(value)
  -> self

Map published values to a boolean based on whether or not it equals the specified value.

Parameters:

NameTypeDescription
valueTThe value to compare with

Returns:

TypeDescription
self

ToBooleanGreaterThanOrEquals

lua
function ReactivePublisherSchemaBase:ToBooleanGreaterThanOrEquals(value)
  -> self

Map published values to a boolean based on whether or not it is greater than or equal to the specified value.

Parameters:

NameTypeDescription
valueTThe value to compare with

Returns:

TypeDescription
self

ToBooleanLessThanOrEquals

lua
function ReactivePublisherSchemaBase:ToBooleanLessThanOrEquals(value)
  -> self

Map published values to a boolean based on whether or not it is less than or equal to the specified value.

Parameters:

NameTypeDescription
valueTThe value to compare with

Returns:

TypeDescription
self

ToBooleanNotEquals

lua
function ReactivePublisherSchemaBase:ToBooleanNotEquals(value)
  -> self

Map published values to a boolean based on whether or not it equals the specified value.

Parameters:

NameTypeDescription
valueTThe value to compare with

Returns:

TypeDescription
self

ToStringFormat

lua
function ReactivePublisherSchemaBase:ToStringFormat(formatStr)
  -> self

Map published values as arguments to a format string.

Parameters:

NameTypeDescription
formatStrstringThe string to format with the published values

Returns:

TypeDescription
self

_AddStepHelper

lua
function ReactivePublisherSchemaBase:_AddStepHelper(stepType, ...)
  -> self

Parameters:

NameTypeDescription
stepTypeEnumValue
...any

Returns:

TypeDescription
self

__init

lua
function ReactivePublisherSchemaBase:__init(isShared)

Parameters:

NameTypeDescription
isShared``

Inherits: ReactivePublisherSchemaBase, Class

Methods

AssignToTableKey

lua
function ReactivePublisherSchema:AssignToTableKey(tbl, key)
  -> ReactivePublisher

Assigns published values to the specified key in the table.

Parameters:

NameTypeDescription
tblTBLThe table to assign the published values into
keyKThe key to assign the published values at

Returns:

TypeDescription
ReactivePublisher

CallFunction

lua
function ReactivePublisherSchema:CallFunction(func, arg)
  -> ReactivePublisher

Calls a function with the published values.

Parameters:

NameTypeDescription
funcfun(value: T)The function to call with the published values
arganyAn additional argument to pass to the function

Returns:

TypeDescription
ReactivePublisher

CallMethod

lua
function ReactivePublisherSchema:CallMethod(obj, method, arg)
  -> ReactivePublisher

Calls a method with the published values.

Parameters:

NameTypeDescription
objObjThe object to call the method on
methodKThe name of the method to call with the published values
arganyAn additional argument to pass to the method

Returns:

TypeDescription
ReactivePublisher

FlatMapCallFunction

lua
function ReactivePublisherSchema:FlatMapCallFunction(map, func, arg)
  -> ReactivePublisher

Maps published values to a new publisher which is owned by the current publisher and call a function with values it publishes.

Parameters:

NameTypeDescription
mapReactivePublisherFlatMapFunc<T>A function which takes a published value and returns a new publisher
funcfun(value: any)The function to call with the published values
arganyAn additional argument to pass to the function

Returns:

TypeDescription
ReactivePublisher

FlatMapCallMethod

lua
function ReactivePublisherSchema:FlatMapCallMethod(map, obj, method, arg)
  -> ReactivePublisher

Maps published values to a new publisher which is owned by the current publisher and call a method with values it publishes.

Parameters:

NameTypeDescription
mapReactivePublisherFlatMapFunc<T>A function which takes a published value and returns a new publisher
objtableThe object to call the method on
methodstringThe name of the method to call with the published values
arganyAn additional argument to pass to the method

Returns:

TypeDescription
ReactivePublisher

Share

lua
function ReactivePublisherSchema:Share()
  -> ReactivePublisherSchemaShared

Shares the result of the publisher at the current point in the chain.

Returns:

TypeDescription
ReactivePublisherSchemaShared

_Acquire

lua
function ReactivePublisherSchema:_Acquire(subject)

Parameters:

NameTypeDescription
subjectReactiveSubject<T>

_AddStepHelper

lua
function ReactivePublisherSchema:_AddStepHelper(stepType, ...)

Parameters:

NameTypeDescription
stepType``
...``

_Commit

lua
function ReactivePublisherSchema:_Commit()

_Release

lua
function ReactivePublisherSchema:_Release()

__init

lua
function ReactivePublisherSchema:__init()

Functions

Get

lua
function ReactivePublisherSchema.Get(subject)
  -> ReactivePublisherSchema

Gets a publisher schema object.

Parameters:

NameTypeDescription
subjectReactiveSubject<T>The subject which is publishing values

Returns:

TypeDescription
ReactivePublisherSchema

Inherits: ReactivePublisherSchemaBase, Class

Methods

AssignToTableKey

lua
function ReactivePublisherSchemaShared:AssignToTableKey(tbl, key)
  -> self

Assigns published values to the specified key in the table.

Parameters:

NameTypeDescription
tbltableThe table to assign the published values into
keystringThe key to assign the published values at

Returns:

TypeDescription
self

CallFunction

lua
function ReactivePublisherSchemaShared:CallFunction(func, arg)
  -> self

Calls a function with the published values.

Parameters:

NameTypeDescription
funcfun(value: TCur, arg: A)The function to call with the published values
argAAn additional argument to pass to the function

Returns:

TypeDescription
self

CallMethod

lua
function ReactivePublisherSchemaShared:CallMethod(obj, method, arg)
  -> self

Calls a method with the published values.

Parameters:

NameTypeDescription
objObjThe object to call the method on
methodKThe name of the method to call with the published values
arganyAn additional argument to pass to the method

Returns:

TypeDescription
self

EndShare

lua
function ReactivePublisherSchemaShared:EndShare()
  -> ReactivePublisher

Ends the share.

Returns:

TypeDescription
ReactivePublisher

FlatMapCallFunction

lua
function ReactivePublisherSchemaShared:FlatMapCallFunction(map, func, arg)
  -> self

Maps published values to a new publisher which is owned by the current publisher and call a function with values it publishes.

Parameters:

NameTypeDescription
mapReactivePublisherFlatMapFunc<TCur>A function which takes a published value and returns a new publisher
funcfun(value: TCur, arg: A)The function to call with the published values
argAAn additional argument to pass to the function

Returns:

TypeDescription
self

FlatMapCallMethod

lua
function ReactivePublisherSchemaShared:FlatMapCallMethod(map, obj, method, arg)
  -> self

Maps published values to a new publisher which is owned by the current publisher and call a method with values it publishes.

Parameters:

NameTypeDescription
mapReactivePublisherFlatMapFunc<TCur>A function which takes a published value and returns a new publisher
objObjThe object to call the method on
methodKThe name of the method to call with the published values
arganyAn additional argument to pass to the method

Returns:

TypeDescription
self

_Acquire

lua
function ReactivePublisherSchemaShared:_Acquire(parentSchema, codeGen)

Parameters:

NameTypeDescription
parentSchemaReactivePublisherSchemaBase
codeGenReactivePublisherCodeGen

_AddStepHelper

lua
function ReactivePublisherSchemaShared:_AddStepHelper(stepType, ...)

Parameters:

NameTypeDescription
stepType``
...``

_Commit

lua
function ReactivePublisherSchemaShared:_Commit()

_Release

lua
function ReactivePublisherSchemaShared:_Release()

__init

lua
function ReactivePublisherSchemaShared:__init()

Functions

Get

lua
function ReactivePublisherSchemaShared.Get(parentSchema, codeGen)
  -> ReactivePublisherSchemaShared

Gets a shared publisher schema object.

Parameters:

NameTypeDescription
parentSchemaReactivePublisherSchemaBaseThe parent schema which is being shared
codeGenReactivePublisherCodeGenThe code gen object to add steps to

Returns:

TypeDescription
ReactivePublisherSchemaShared