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 )): MixinFields
| Name | Type | Description |
|---|---|---|
name | string | The name of the mixin. |
Methods
attach | Attaches a handler (or nested Mixin) to the end of the chain. |
call | Runs every handler in the chain in order, passing each one the running old_value/new_value pair plus any extra argument… |
detach | Detaches a previously attached handler from the chain. |
#Mixin:attach
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).
| Name | Type | Description |
|---|---|---|
mixer | ( fun( old_value: ( T | nil ), new: T, ...: any ): ( T | nil ) ) | Mixin<T> | The handler to attach. |
| Type | Name | Description |
|---|---|---|
integer | depth | The handler's position in the chain after attaching. |
#Mixin:call
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.
| Name | Type | Description |
|---|---|---|
old_value | T | nil | The previous value, if any. |
new_value | T | The current value to transform. |
... | any | Extra arguments forwarded to every handler. |
| Type | Name | Description |
|---|---|---|
T | new_value | The final value after all handlers have run. |
#Mixin:detach
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.
| Name | Type | Description |
|---|---|---|
mixer | ( fun( old_value: ( T | nil ), new: T, ...: any ): ( T | nil ) ) | Mixin<T> | The exact handler reference that was previously passed to attach. |
| Type | Name | Description |
|---|---|---|
boolean | is_detached | Returns true if the handler was found and detached, otherwise false. |