Skip to main content

StateStack

Stack of values that allows multiple systems to enable or disable a state.

local disabledStack = maid:Add(StateStack.new(false, "boolean"))
print(disabledStack:GetState()) --> false

maid:GiveTask(disabledStack.Changed:Connect(function()
	print("From changed event we have state: ", disabledStack:GetState())
end))

local cancel = disabledStack:PushState(true) --> From changed event we have state: true
print(disabledStack:GetState()) --> true

cancel()  --> From changed event we have state: true
print(disabledStack:GetState()) --> false

disabledStack:Destroy()

Properties

Changed

StateStack.Changed: Signal<T>

Fires with the new state

Functions

new

StateStack.new(
defaultValueany,--

The default value to use for the statestack.

checkTypestring | nil
) → StateStack

Constructs a new StateStack.

GetCount

StateStack:GetCount() → number

Gets the count of the stack

GetState

StateStack:GetState() → T?

Gets the current state

Observe

StateStack:Observe() → Observable<T?>

Observes the current value of stack

ObserveBrio

StateStack:ObserveBrio(predicatefunction) → Observable<T?>

Observes the current value of stack

PushState

StateStack:PushState(stateT?) → function--

Cleanup function to invoke

Pushes the current state onto the stack

PushBrio

StateStack:PushBrio(brioBrio) → function--

Cleanup function

Pushes the brio's content onto the stack for the lifetime of the brio

Destroy

StateStack:Destroy() → ()

Cleans up the StateStack and sets the metatable to nil.

tip

Be sure to call this to clean up the state stack!

Show raw api
{
    "functions": [
        {
            "name": "new",
            "desc": "Constructs a new StateStack.",
            "params": [
                {
                    "name": "defaultValue",
                    "desc": "The default value to use for the statestack.",
                    "lua_type": "any"
                },
                {
                    "name": "checkType",
                    "desc": "",
                    "lua_type": "string | nil"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "StateStack"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 39,
                "path": "src/statestack/src/Shared/StateStack.lua"
            }
        },
        {
            "name": "GetCount",
            "desc": "Gets the count of the stack",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 60,
                "path": "src/statestack/src/Shared/StateStack.lua"
            }
        },
        {
            "name": "GetState",
            "desc": "Gets the current state",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "T?"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 68,
                "path": "src/statestack/src/Shared/StateStack.lua"
            }
        },
        {
            "name": "Observe",
            "desc": "Observes the current value of stack",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Observable<T?>"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 76,
                "path": "src/statestack/src/Shared/StateStack.lua"
            }
        },
        {
            "name": "ObserveBrio",
            "desc": "Observes the current value of stack",
            "params": [
                {
                    "name": "predicate",
                    "desc": "",
                    "lua_type": "function"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Observable<T?>"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 85,
                "path": "src/statestack/src/Shared/StateStack.lua"
            }
        },
        {
            "name": "PushState",
            "desc": "Pushes the current state onto the stack",
            "params": [
                {
                    "name": "state",
                    "desc": "",
                    "lua_type": "T?"
                }
            ],
            "returns": [
                {
                    "desc": "Cleanup function to invoke",
                    "lua_type": "function"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 94,
                "path": "src/statestack/src/Shared/StateStack.lua"
            }
        },
        {
            "name": "PushBrio",
            "desc": "Pushes the brio's content onto the stack for the lifetime of the brio",
            "params": [
                {
                    "name": "brio",
                    "desc": "",
                    "lua_type": "Brio"
                }
            ],
            "returns": [
                {
                    "desc": "Cleanup function",
                    "lua_type": "function"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 112,
                "path": "src/statestack/src/Shared/StateStack.lua"
            }
        },
        {
            "name": "Destroy",
            "desc": "Cleans up the StateStack and sets the metatable to nil.\n\n:::tip\nBe sure to call this to clean up the state stack!\n:::",
            "params": [],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 159,
                "path": "src/statestack/src/Shared/StateStack.lua"
            }
        }
    ],
    "properties": [
        {
            "name": "Changed",
            "desc": "Fires with the new state",
            "lua_type": "Signal<T>",
            "source": {
                "line": 51,
                "path": "src/statestack/src/Shared/StateStack.lua"
            }
        }
    ],
    "types": [],
    "name": "StateStack",
    "desc": "Stack of values that allows multiple systems to enable or disable a state.\n\n```lua\nlocal disabledStack = maid:Add(StateStack.new(false, \"boolean\"))\nprint(disabledStack:GetState()) --> false\n\nmaid:GiveTask(disabledStack.Changed:Connect(function()\n\tprint(\"From changed event we have state: \", disabledStack:GetState())\nend))\n\nlocal cancel = disabledStack:PushState(true) --> From changed event we have state: true\nprint(disabledStack:GetState()) --> true\n\ncancel()  --> From changed event we have state: true\nprint(disabledStack:GetState()) --> false\n\ndisabledStack:Destroy()\n```",
    "source": {
        "line": 23,
        "path": "src/statestack/src/Shared/StateStack.lua"
    }
}