getState :function
function getState(Scope: Scope): (inputValue: CanBeState<any>, defaultValue: CanBeState<any>, mustBeKind: string?) -> CanBeState<any>
This utility function ensures that you get the correct Fusion object type at all costs.
- If the input type is a
State
, and themustBeKind
is also set to "State", then theinputValue
will be returned. - If the input type is a
State
, but themustBeKind
is set to something else, then the utility function will create a new object from the kind set in themustBeKind
, with the value from theinputValue
, and return it. - If both of these are false, but the
defaultValue
is aState
, then thedefaultValue
will be returned. - If all of the above are false, but the
defaultValue
still exists, then the utility function will create a new object from the kind either set in themustBeKind
, or the kind "Value" by default, with the value from thedefaultValue
and return it.
Default Syntax
local getStateUtility = require(StudioComponents.Util.getState)
local getState = getStateUtility(Scope)
Shorthand
Parameters
Scope: Scope
The
Scope
the utility function will be initialized in.
Returns Function
Parameters
inputValue: CanBeState<any>
The input value to be checked.
defaultValue: CanBeState<any>
If the input value is not provided or not valid, then this value will be used.
mustBeKind: string?
This parameter ensures that the provided values must be a certain Fusion type.
Returns
CanBeState<any>