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(
defaultValue: any,--

The default value to use for the statestack.

checkType: string?
) → StateStack

Constructs a new StateStack.

GetCount​

StateStack.GetCount(self: StateStack<T>) → number

Gets the count of the stack

GetState​

StateStack.GetState(self: StateStack<T>) → T

Gets the current state

Observe​

StateStack.Observe(self: StateStack<T>) → Observable<T>

Observes the current value of stack

ObserveBrio​

StateStack.ObserveBrio(
self: StateStack<T>,
predicate: function
) → Observable<T>

Observes the current value of stack

PushState​

StateStack.PushState(
self: StateStack<T>,
state: T
) → function--

Cleanup function to invoke

Pushes the current state onto the stack

PushBrio​

StateStack.PushBrio(
self: StateStack<T>,
brio: Brio
) → 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?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "StateStack"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 57,
                "path": "src/statestack/src/Shared/StateStack.lua"
            }
        },
        {
            "name": "GetCount",
            "desc": "Gets the count of the stack",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "StateStack<T>"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 78,
                "path": "src/statestack/src/Shared/StateStack.lua"
            }
        },
        {
            "name": "GetState",
            "desc": "Gets the current state",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "StateStack<T>"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "T"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 86,
                "path": "src/statestack/src/Shared/StateStack.lua"
            }
        },
        {
            "name": "Observe",
            "desc": "Observes the current value of stack",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "StateStack<T>"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Observable<T>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 94,
                "path": "src/statestack/src/Shared/StateStack.lua"
            }
        },
        {
            "name": "ObserveBrio",
            "desc": "Observes the current value of stack",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "StateStack<T>"
                },
                {
                    "name": "predicate",
                    "desc": "",
                    "lua_type": "function"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Observable<T>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 103,
                "path": "src/statestack/src/Shared/StateStack.lua"
            }
        },
        {
            "name": "PushState",
            "desc": "Pushes the current state onto the stack",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "StateStack<T>"
                },
                {
                    "name": "state",
                    "desc": "",
                    "lua_type": "T"
                }
            ],
            "returns": [
                {
                    "desc": "Cleanup function to invoke",
                    "lua_type": "function"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 112,
                "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": "self",
                    "desc": "",
                    "lua_type": "StateStack<T>"
                },
                {
                    "name": "brio",
                    "desc": "",
                    "lua_type": "Brio"
                }
            ],
            "returns": [
                {
                    "desc": "Cleanup function",
                    "lua_type": "function"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 130,
                "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": 177,
                "path": "src/statestack/src/Shared/StateStack.lua"
            }
        }
    ],
    "properties": [
        {
            "name": "Changed",
            "desc": "Fires with the new state",
            "lua_type": "Signal<T>",
            "source": {
                "line": 69,
                "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": 24,
        "path": "src/statestack/src/Shared/StateStack.lua"
    }
}