Skip to main content

ValueObject

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

Functions

new

ValueObject.new(
baseValueT,
checkTypestring? | (valueT) → (
boolean,
string?
)
) → ValueObject

Constructs a new value object

GetCheckType

ValueObject.GetCheckType(selfValueObject<T>) → string? | (valueT) → (
boolean,
string
)

Returns the current check type, if any

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

Mount

ValueObject.Mount(
selfValueObject<T>,
valueObservable | T
) → MaidTask

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

Observe

ValueObject.Observe(selfValueObject<T>) → Observable<T?>

Observes the current value of the ValueObject

ObserveBrio

ValueObject.ObserveBrio(
selfValueObject<T>,
conditionfunction | nil--

optional

) → Observable<Brio<T>>

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

SetValue

ValueObject.SetValue(
selfValueObject<T>,
valueT,
...any--

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

) → () → ()--

Cleanup

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(selfValueObject<T>) → ()

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? | (value: T) -> (boolean, string?)"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "ValueObject"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 62,
                "path": "src/valueobject/src/Shared/ValueObject.lua"
            }
        },
        {
            "name": "GetCheckType",
            "desc": "Returns the current check type, if any",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "ValueObject<T>"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "string? | (value: T) -> (boolean, string)"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 88,
                "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": 97,
                "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": 110,
                "path": "src/valueobject/src/Shared/ValueObject.lua"
            }
        },
        {
            "name": "Mount",
            "desc": "Mounts the value to the observable. Overrides the last mount.",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "ValueObject<T>"
                },
                {
                    "name": "value",
                    "desc": "",
                    "lua_type": "Observable | T"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "MaidTask"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 139,
                "path": "src/valueobject/src/Shared/ValueObject.lua"
            }
        },
        {
            "name": "Observe",
            "desc": "Observes the current value of the ValueObject",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "ValueObject<T>"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Observable<T?>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 176,
                "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": "self",
                    "desc": "",
                    "lua_type": "ValueObject<T>"
                },
                {
                    "name": "condition",
                    "desc": "optional",
                    "lua_type": "function | nil"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Observable<Brio<T>>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 216,
                "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": "self",
                    "desc": "",
                    "lua_type": "ValueObject<T>"
                },
                {
                    "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": [
                {
                    "desc": "Cleanup",
                    "lua_type": "() -> ()"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 273,
                "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": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "ValueObject<T>"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 356,
                "path": "src/valueobject/src/Shared/ValueObject.lua"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "ValueObject",
    "desc": "To work like value objects in Roblox and track a single item,\nwith `.Changed` events",
    "source": {
        "line": 7,
        "path": "src/valueobject/src/Shared/ValueObject.lua"
    }
}