This JavaScript function exposes the basic behavior of Origami templates, especially their ability to concatenate the deep values of an asynchronous tree.
By default, JavaScript templates don’t perform useful work on inputs that are objects, rendering objects unhelpfully as "[object Object]"
.
The deepText
tagged template function can be called to concatenate the values of a treelike object such as a plain JavaScript object:
import { deepText } from "@weborigami/async-tree";
const object = {
Alice: "Hello, Alice!",
Bob: "Hello, Bob!",
Carol: "Hello, Carol!",
};
const text = await deepText`${object}`;
export default text;
Since deepText
is a tagged template function, it is followed immediately by a backtick instead of an opening parenthesis. Also note the use of await
, since deepText
is an asynchronous function.
The above module exports this string:
Hello, Alice!Hello, Bob!Hello, Carol!