Skip to main content

State

Observable

Inherits Observable

Writeable observable which holds a value which can be re-assigned via State:Set

Constructor


Dex.State

Dex.State<T>(initialValue: T) -> State<T>

Creates a new State observable with the given initial value, matching the type of the value passed in.

If you pass in nil or table with optional values as the inital value, you should give the initial value a type annotation:

local notification = Dex.State(nil :: {
    id: string,
    message: string,
}?)

-- . . . OK
notification:Set({id = "Foo", message = "Fighters"})

-- . . . Also OK
notification:Set(nil)

-- Will always be of type `{id: string, message: string}?`
local currentNotification = notification:Current()

Functions

Set

State:Set(valueT) → ()

Updates the state's current value.

Show raw api
{
    "functions": [
        {
            "name": "Set",
            "desc": "Updates the state's current value.",
            "params": [
                {
                    "name": "value",
                    "desc": "",
                    "lua_type": "T"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 70,
                "path": "src/Observables/State.luau"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "State",
    "desc": "#### Inherits [Observable]\n\nWriteable observable which holds a value which can be re-assigned via\n[State:Set]\n\n## Constructor\n\n---\n\n### Dex.State\n\n```ts\nDex.State<T>(initialValue: T) -> State<T>\n```\n\nCreates a new [State] observable with the given initial value,\nmatching the type of the value passed in.\n\nIf you pass in `nil` or table with optional values as the inital value, you\nshould give the initial value a type annotation:\n```lua\nlocal notification = Dex.State(nil :: {\n    id: string,\n    message: string,\n}?)\n\n-- . . . OK\nnotification:Set({id = \"Foo\", message = \"Fighters\"})\n\n-- . . . Also OK\nnotification:Set(nil)\n\n-- Will always be of type `{id: string, message: string}?`\nlocal currentNotification = notification:Current()\n```",
    "tags": [
        "Observable"
    ],
    "source": {
        "line": 48,
        "path": "src/Observables/State.luau"
    }
}