@blaze-ng/templating-runtime
Template registration, body content management, dynamic templates, and HMR support.
Installation
npm install @blaze-ng/templating-runtimeTemplate Registration
__define__()
Register a named template with a render function.
function __define__(name: string, renderFunc: () => unknown): void;import { __define__ } from '@blaze-ng/templating-runtime';
__define__('myComponent', function () {
const view = this;
return HTML.DIV({ class: 'component' }, Spacebars.mustache(view.lookup('content')));
});__checkName()
Validate a template name is not already registered.
function __checkName(name: string): void;Throws if the template name is already in use.
getRegisteredTemplate()
Retrieve a registered template by name.
function getRegisteredTemplate(name: string): Template | undefined;import { getRegisteredTemplate } from '@blaze-ng/templating-runtime';
const tmpl = getRegisteredTemplate('myComponent');
if (tmpl) {
Blaze.render(tmpl, document.body);
}Body Content
addBodyContent()
Add content to the document body template.
function addBodyContent(renderFunc: () => unknown): void;renderToDocument()
Render all registered body content into the document.
function renderToDocument(): void;getBodyView()
Get the view for the rendered body content.
function getBodyView(): View | null;body
The Template.body template instance for body content.
const body: Template;Dynamic Templates
__dynamic
Helper for {{> Template.dynamic}}:
__dynamicWithDataContext
Helper for dynamic templates with explicit data context:
HMR (Hot Module Replacement)
_applyHmrChanges()
Apply hot module replacement changes to templates.
function _applyHmrChanges(templateName?: string): void;_migrateTemplate()
Migrate a template to a new version during HMR.
function _migrateTemplate(templateName: string, newTemplate: Template): void;_markPendingReplacement()
Mark a template as pending replacement during HMR.
function _markPendingReplacement(name: string): void;Testing
_resetRegistry()
Clear all registered templates. Useful for test cleanup.
function _resetRegistry(): void;import { _resetRegistry } from '@blaze-ng/templating-runtime';
afterEach(() => {
_resetRegistry();
});