Take
Take determines the input fields that will be supplied to the make
function. It is a flat array of field objects.
export const take = [
{ type: "text", value: "String" },
{ type: "toggle", value: true },
{ type: "number", value: 123 },
]
The code above will render three fields — a text
field, a toggle
and a number
field.
Short-hand statements
If only one input is needed, there is no need to wrap the field in an array. Instead, pass it directly to take
.
export const take = { type: "json" }
Functions
When needed, take
may also be a function that returns such an array or object.
export const take = function () {
return {
type: "dropdown",
options: ["Small", "Medium", "Large"],
}
}
If you need to run an asynchronous process, take
can be an async function or return a Promise.
// Declare an async function
export const take = async () => {
const request = await fetch("https://example.com/some/json")
return await request.json()
}
// Return a Promise
export const take = () => {
return new Promise(function (resolve) {
resolve([{ type: "text" }])
})
}
Default value
When take
is null or undefined, the default input is a single text
field.
// A make function with no take definition
export const make = (data) => {
return typeof data // => "string"
}
No inputs
If no inputs are necessary, you can set the value to an empty array. In this case, no input fields are rendered.
export const take = []