Skip to content
TwitterDiscordGitHub

Context

Context in HMPL is a concept that describes the environment of a certain block.

This context describes the environment within a single specific request.

PropertyTypeDescription
eventEvent | undefinedThis property provides access to the event object described in the after attribute
clearIntervalHMPLClearInterval | undefinedRequired to stop the interval described in the corresponding attribute
const templateFn = hmpl.compile(
`<div>
<button data-action="increment" id="btn">Click!</button>
<div>Clicks: {{#request src="/api/clicks" interval=1000 after="click:#btn"}}{{/request}}</div>
</div>`
);
const elementObj = templateFn({
get: (prop, value, context, request) => {
console.log(context);
}
});
Preview

{ request: { event: Event, clearInterval: () => void } }