/workspace/getTemplate
The module exports the getTemplate method which is required by the query, languageTemplates, getLayer, and getLocale modules.
- Source
Requires
Methods
(async, inner) getTemplate(template) → {Promise.<(Object|Error)>}
The workspace will be checked and cached by the Workspace API checkWorkspaceCache method.
The template parameter provided as a string from user input must be validated to only include whitelisted character.
A lookup for the template object in the cached workspace.templates{} will be performed.
Templates without a src property will be returned immediately.
The template src response is retrieved from the workspace source map. The first request stores its provider promise before awaiting so concurrent requests share one fetch.
A module template will be created from the cached source response with the template.module flag.
The source response will be composed into a clone of the template definition. The assembled template is loaded into the workspace.templates{} object with the srcLoaded flag. Repeat requests for the template are resolved from the workspace.templates{} object without reading the source again.
A structured clone of the template will be returned to prevent the cached object being modified by role merges. Module templates are not loaded into the workspace.templates{} object.
| Name | Type | Description |
|---|---|---|
template | string | | to be retrieved from workspace.templates if provided as string |
- Source
JSON Template
- Type:
- Promise.<(Object|Error)>
(async, inner) moduleTemplate(template, response) → {Promise.<(Object|Error)>}
The script string is converted to a JavaScript data URL which can be used in a dynamic ESM import.
The default export or the imported module itself will be assigned as the render method in the module template.
Module templates are not cached.
| Name | Type | Description |
|---|---|---|
template | object | |
response | string | Module script as string. |
- Source
JSON Template
- Type:
- Promise.<(Object|Error)>