Skip to content

Instance

An object returned from the template function that contains data from the responses to requests.

Property Type Description
response undefined | Element | null Compiled element from template
status HMPLRequestStatus The status of the response to the request. If there are several requests in the template, this property is not included in the object
requests HMPLRequest[] Contains information for each request in the template. If the template contains only one request, this property is not included in the object
const instance = templateFn();
console.log(instance);
Preview

{ status: 200, response: div }

The value is the Element compiled from the template. If the template does not have a container tag, the response comes as a template tag with HTML from the server.

const templateFn = compile(`<div>{{#r src="/test"}}{{/r}}</div>`);
const instance = templateFn();
console.log(instance);
Preview
<div>
<span>My component</span>
</div>

Contains all HTTP request codes, as well as states such as "pending" and "rejected".

const instance = templateFn();
console.log(instance.status);
Preview
200

Contains an array of information objects about each request in the template.

const templateFn = compile(
`<div>{{#r src="/test1"}}{{/r}}{{#r src="/test2"}}{{/r}}</div>`
);
const instance = templateFn();
console.log(instance);
Preview
{
response: div,
requests: [
{ status: 200, response: b },
{ status: 200, response: [a, div] }
]
}