Skip to main content

ValueObject

To work like value objects in Roblox and track a single item, with .Changed events

Properties

Changed

ValueObject.Changed: Signal<T>--fireswitholdValue,newValue,...

Event fires when the value's object value change

Value

ValueObject.Value: T

The value of the ValueObject

Functions

new

ValueObject.new(
baseValueT,
checkTypestring | nil
) → ValueObject

Constructs a new value object

fromObservable

ValueObject.fromObservable(observableObservable<T>) → ValueObject<T>

Constructs a new value object

isValueObject

ValueObject.isValueObject(valueany) → boolean

Returns whether the object is a ValueObject class

GetCheckType

ValueObject:GetCheckType() → string | nil

Returns the current check type, if any

Mount

ValueObject:Mount(valueObservable | T) → MaidTask

Mounts the value to the observable. Overrides the last mount.

Observe

ValueObject:Observe() → Observable<T>

Observes the current value of the ValueObject

ObserveBrio

ValueObject:ObserveBrio(
conditionfunction | nil--

optional

) → Observable<Brio<T>>

Observes the value as a brio. The condition defaults to truthy or nil.

SetValue

ValueObject:SetValue(
valueT,
...any--

Additional args. Can be used to pass event changing state args with value

) → ()

Allows you to set a value, and provide additional event context for the actual change. For example, you might do.

self.IsVisible:SetValue(isVisible, true)

print(self.IsVisible.Changed:Connect(function(isVisible, _, doNotAnimate)
	print(doNotAnimate)
end))

Destroy

ValueObject:Destroy() → ()

Forces the value to be nil on cleanup, cleans up the Maid

Does not fire the event since 3.5.0

Show raw api
{
    "functions": [
        {
            "name": "new",
            "desc": "Constructs a new value object",
            "params": [
                {
                    "name": "baseValue",
                    "desc": "",
                    "lua_type": "T"
                },
                {
                    "name": "checkType",
                    "desc": "",
                    "lua_type": "string | nil"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "ValueObject"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 28,
                "path": "src/valueobject/src/Shared/ValueObject.lua"
            }
        },
        {
            "name": "GetCheckType",
            "desc": "Returns the current check type, if any",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "string | nil"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 55,
                "path": "src/valueobject/src/Shared/ValueObject.lua"
            }
        },
        {
            "name": "fromObservable",
            "desc": "Constructs a new value object",
            "params": [
                {
                    "name": "observable",
                    "desc": "",
                    "lua_type": "Observable<T>"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "ValueObject<T>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 64,
                "path": "src/valueobject/src/Shared/ValueObject.lua"
            }
        },
        {
            "name": "isValueObject",
            "desc": "Returns whether the object is a ValueObject class",
            "params": [
                {
                    "name": "value",
                    "desc": "",
                    "lua_type": "any"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 77,
                "path": "src/valueobject/src/Shared/ValueObject.lua"
            }
        },
        {
            "name": "Mount",
            "desc": "Mounts the value to the observable. Overrides the last mount.",
            "params": [
                {
                    "name": "value",
                    "desc": "",
                    "lua_type": "Observable | T"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "MaidTask"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 105,
                "path": "src/valueobject/src/Shared/ValueObject.lua"
            }
        },
        {
            "name": "Observe",
            "desc": "Observes the current value of the ValueObject",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Observable<T>"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 142,
                "path": "src/valueobject/src/Shared/ValueObject.lua"
            }
        },
        {
            "name": "ObserveBrio",
            "desc": "Observes the value as a brio. The condition defaults to truthy or nil.",
            "params": [
                {
                    "name": "condition",
                    "desc": "optional",
                    "lua_type": "function | nil"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Observable<Brio<T>>"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 174,
                "path": "src/valueobject/src/Shared/ValueObject.lua"
            }
        },
        {
            "name": "SetValue",
            "desc": "Allows you to set a value, and provide additional event context for the actual change.\nFor example, you might do.\n\n```lua\nself.IsVisible:SetValue(isVisible, true)\n\nprint(self.IsVisible.Changed:Connect(function(isVisible, _, doNotAnimate)\n\tprint(doNotAnimate)\nend))\n```",
            "params": [
                {
                    "name": "value",
                    "desc": "",
                    "lua_type": "T"
                },
                {
                    "name": "...",
                    "desc": "Additional args. Can be used to pass event changing state args with value",
                    "lua_type": "any"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 227,
                "path": "src/valueobject/src/Shared/ValueObject.lua"
            }
        },
        {
            "name": "Destroy",
            "desc": "Forces the value to be nil on cleanup, cleans up the Maid\n\nDoes not fire the event since 3.5.0",
            "params": [],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 288,
                "path": "src/valueobject/src/Shared/ValueObject.lua"
            }
        }
    ],
    "properties": [
        {
            "name": "Changed",
            "desc": "Event fires when the value's object value change",
            "lua_type": "Signal<T> -- fires with oldValue, newValue, ...",
            "source": {
                "line": 44,
                "path": "src/valueobject/src/Shared/ValueObject.lua"
            }
        },
        {
            "name": "Value",
            "desc": "The value of the ValueObject",
            "lua_type": "T",
            "source": {
                "line": 253,
                "path": "src/valueobject/src/Shared/ValueObject.lua"
            }
        }
    ],
    "types": [],
    "name": "ValueObject",
    "desc": "To work like value objects in Roblox and track a single item,\nwith `.Changed` events",
    "source": {
        "line": 6,
        "path": "src/valueobject/src/Shared/ValueObject.lua"
    }
}