mirror of
https://github.com/lowdefy/lowdefy.git
synced 2025-02-23 14:39:32 +08:00
113 lines
4.1 KiB
YAML
113 lines
4.1 KiB
YAML
# Copyright 2020-2021 Lowdefy, Inc
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
_ref:
|
|
path: templates/operators.yaml.njk
|
|
transformer: templates/operatorsMethodTransformer.js
|
|
vars:
|
|
pageId: _input
|
|
pageTitle: _input
|
|
types: |
|
|
```
|
|
(key: string): any
|
|
(all: boolean): any
|
|
(arguments: {
|
|
all?: boolean,
|
|
key?: string,
|
|
default?: any,
|
|
contextId?: string
|
|
}): any
|
|
```
|
|
description: |
|
|
The `_input` operator gets a value from the [`input`](/context-and-state) object. The `input` is a data object that can be set when linking to a new page using the [`Link`](/link) action, and can be used to set data like a `id` when switching to a new page. Unlike `urlQuery`, the `input` is not visible, and cannot be changed by the user, but if the page is reloaded, the `input` is lost. By default, `_input` accesses the `input` object from the [`context`](/context-and-state) the operator is used in, but a different context can be specified.
|
|
|
|
arguments: |
|
|
###### string
|
|
If the `_input` operator is called with a string argument, the value of the key in the `input` object is returned. If the value is not found, `null` is returned. Dot notation and [block list indexes](/lists) are supported.
|
|
|
|
###### boolean
|
|
If the `_input` operator is called with boolean argument `true`, the entire `input` object is returned.
|
|
|
|
###### object
|
|
- `all: boolean`: If `all` is set to `true`, the entire `input` object is returned. One of `all` or `key` are required.
|
|
- `key: string`: The value of the key in the `input` object is returned. If the value is not found, `null`, or the specified default value is returned. Dot notation and [block list indexes](/lists) are supported. One of `all` or `key` are required.
|
|
- `default: any`: A value to return if the `key` is not found in `input`. By default, `null` is returned if a value is not found.
|
|
- `contextId: string`: The id of a `context`. Setting this will get the value from the `input` of the specified context. A list of `contexts` that exist are returned by the [`_list_contexts`](/_list_contexts) operator. Cannot be used in `connections` or `requests`.
|
|
examples: |
|
|
###### Get the value of `my_key` from `input`:
|
|
```yaml
|
|
_input: my_key
|
|
```
|
|
```yaml
|
|
_input:
|
|
key: my_key
|
|
```
|
|
Returns: The value of `my_key` in `input`.
|
|
|
|
###### Get the entire `input` object:
|
|
```yaml
|
|
_input: true
|
|
```
|
|
```yaml
|
|
_input:
|
|
all: true
|
|
```
|
|
Returns: The entire `input` object.
|
|
|
|
###### Dot notation:
|
|
Assuming input:
|
|
```yaml
|
|
my_object:
|
|
subfield: 'Value'
|
|
```
|
|
then:
|
|
```yaml
|
|
_input: my_object.subfield
|
|
```
|
|
```yaml
|
|
_input:
|
|
key: my_object.subfield
|
|
```
|
|
Returns: `"Value"`.
|
|
|
|
###### Return a default value if the value is not found:
|
|
```yaml
|
|
_input:
|
|
key: might_not_exist
|
|
default: Default value
|
|
```
|
|
Returns: The value of `might_not_exist`, or `"Default value"`.
|
|
|
|
###### Block list indices:
|
|
Assuming `input`:
|
|
```yaml
|
|
my_array:
|
|
- value: 0
|
|
- value: 1
|
|
- value: 2
|
|
```
|
|
then:
|
|
```yaml
|
|
_input: my_array.$.value
|
|
```
|
|
Returns: `0` when used from the first block (0th index) in a list.
|
|
|
|
###### Get a value from another `context`:
|
|
```yaml
|
|
_input:
|
|
key: my_key
|
|
contextId: 'pageId:contextId:{}'
|
|
```
|
|
Returns: The value of `my_key` in `input` in context `contextId` on page `pageId`.
|