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 | (valueT) → (
boolean,
string
)
) → 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 | (valueT) → (
boolean,
string
)

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 | (value: T) -> (boolean, string)"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "ValueObject"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 29,
                "path": "src/valueobject/src/Shared/ValueObject.lua"
            }
        },
        {
            "name": "GetCheckType",
            "desc": "Returns the current check type, if any",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "string | nil | (value: T) -> (boolean, string)"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 57,
                "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": 66,
                "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": 79,
                "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": 108,
                "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": 145,
                "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": 185,
                "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": 238,
                "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": 314,
                "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": 51,
                "path": "src/valueobject/src/Shared/ValueObject.lua"
            }
        },
        {
            "name": "Value",
            "desc": "The value of the ValueObject",
            "lua_type": "T",
            "source": {
                "line": 270,
                "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"
    }
}