(key: string): any
(all: boolean): any
(arguments: {
all?: boolean,
key?: string,
default?: any,
contextId?: string
}): any
The _state
operator gets a value from the state
object. The state
is a data object specific to the context it is in. The value of input
blocks are available in state
, with their blockId
as key. By default, _state
accesses the state
object from the context
the operator is used in, but a different context can be specified.
Arguments
string
If the _state
operator is called with a string argument, the value of the key in the state
object is returned. If the value is not found, null
is returned. Dot notation and block list indexes are supported.
boolean
If the _state
operator is called with boolean argument true
, the entire state
object is returned.
object
all: boolean
: Ifall
is set totrue
, the entirestate
object is returned. One ofall
orkey
are required.key: string
: The value of the key in thestate
object is returned. If the value is not found,null
, or the specified default value is returned. Dot notation and block list indexes are supported. One ofall
orkey
are required.default: any
: A value to return if thekey
is not found instate
. By default,null
is returned if a value is not found.contextId: string
: The id of acontext
. Setting this will get the value from thestate
of the specified context. A list ofcontexts
that exist are returned by the_list_contexts
operator. Cannot be used inconnections
orrequests
.
Examples
Get the value of my_key
from state
:
_state: my_key
_state:
key: my_key
Returns: The value of my_key
in state
.
Get the entire state
object:
_state: true
_state:
all: true
Returns: The entire state
object.
Dot notation:
Assuming state:
my_object:
subfield: 'Value'
then:
_state: my_object.subfield
_state:
key: my_object.subfield
Returns: "Value"
.
Return a default value if the value is not found:
_state:
key: might_not_exist
default: Default value
Returns: The value of might_not_exist
, or "Default value"
.
Block list indices:
Assuming state
:
my_array:
- value: 0
- value: 1
- value: 2
then:
_state: my_array.$.value
Returns: 0
when used from the first block (0th index) in a list.
Get a value from another context
:
_state:
key: my_key
contextId: 'pageId:contextId:{}'
Returns: The value of my_key
in state
in context contextId
on page pageId
.