dreamworkAPI
Ctrl K
GitHub
classDocs / Mixin

Mixin

classsharedmenusource
Object → Mixin

A mixin is an ordered chain of transformer functions.

Each handler in the chain receives the previous (old_value) and current (new_value) values plus any extra arguments, and may return a new value to replace new_value for the next handler in the chain.

Mixins are themselves callable and can be nested inside one another as handlers.

Constructor

Mixin(name: ( string | nil )): Mixin

Fields

NameTypeDescription
namestringThe name of the mixin.

Methods

attachAttaches a handler (or nested Mixin) to the end of the chain.
callRuns every handler in the chain in order, passing each one the running old_value/new_value pair plus any extra argument…
detachDetaches a previously attached handler from the chain.

#Mixin:attach

sharedmenusource
function Mixin:attach(mixer: ( fun( old_value: ( T | nil ), new: T, ...: any ): ( T | nil ) ) | Mixin<T>): integer

Attaches a handler (or nested Mixin) to the end of the chain. If the handler is already attached, it is moved to the end instead of being added twice.

Throws if mixer is not callable, or if attaching it would create a cycle (a Mixin that indirectly contains self).

Parameters
NameTypeDescription
mixer( fun( old_value: ( T | nil ), new: T, ...: any ): ( T | nil ) ) | Mixin<T>The handler to attach.
Returns
TypeNameDescription
integerdepthThe handler's position in the chain after attaching.

#Mixin:call

sharedmenusource
function Mixin:call(old_value: T | nil, new_value: T, ...: any): T

Runs every handler in the chain in order, passing each one the running old_value/new_value pair plus any extra arguments.

Any handler that returns a non-nil result becomes the new new_value for the next handler (with the previous new_value shifted into old_value).

Throws if any handler errors.

Parameters
NameTypeDescription
old_valueT | nilThe previous value, if any.
new_valueTThe current value to transform.
...anyExtra arguments forwarded to every handler.
Returns
TypeNameDescription
Tnew_valueThe final value after all handlers have run.

#Mixin:detach

sharedmenusource
function Mixin:detach(mixer: ( fun( old_value: ( T | nil ), new: T, ...: any ): ( T | nil ) ) | Mixin<T>): boolean

Detaches a previously attached handler from the chain.

Parameters
NameTypeDescription
mixer( fun( old_value: ( T | nil ), new: T, ...: any ): ( T | nil ) ) | Mixin<T>The exact handler reference that was previously passed to attach.
Returns
TypeNameDescription
booleanis_detachedReturns true if the handler was found and detached, otherwise false.
Generated from the dreamwork meta branch.