ember-source
Version:
A JavaScript framework for creating ambitious web applications
139 lines (122 loc) • 3.93 kB
JavaScript
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/no-explicit-any */
/**
* This package contains global context functions for Glimmer. These functions
* are set by the embedding environment and must be set before initial render.
*
* These functions should meet the following criteria:
*
* - Must be provided by the embedder, due to having framework specific
* behaviors (e.g. interop with classic Ember behaviors that should not be
* upstreamed) or to being out of scope for the VM (e.g. scheduling a
* revalidation)
* - Never differ between render roots
* - Never change over time
*
*/
//////////
/**
* Interfaces
*
* TODO: Move these into @glimmer/interfaces, move @glimmer/interfaces to
* @glimmer/internal-interfaces.
*/
//////////
/**
* Schedules a VM revalidation.
*
* Note: this has a default value so that tags can warm themselves when first loaded.
*/
let scheduleRevalidate = () => {};
/**
* Schedules a destructor to run
*
* @param destroyable The destroyable being destroyed
* @param destructor The destructor being scheduled
*/
let scheduleDestroy;
/**
* Finalizes destruction
*
* @param finalizer finalizer function
*/
let scheduleDestroyed;
/**
* Hook to provide iterators for `{{each}}` loops
*
* @param value The value to create an iterator for
*/
let toIterator;
/**
* Hook to specify truthiness within Glimmer templates
*
* @param value The value to convert to a boolean
*/
let toBool;
/**
* Hook for specifying how Glimmer should access properties in cases where it
* needs to. For instance, accessing an object's values in templates.
*
* @param obj The object provided to get a value from
* @param path The path to get the value from
*/
let getProp;
/**
* Hook for specifying how Glimmer should update props in cases where it needs
* to. For instance, when updating a template reference (e.g. 2-way-binding)
*
* @param obj The object provided to get a value from
* @param prop The prop to set the value at
* @param value The value to set the value to
*/
let setProp;
/**
* Hook for specifying how Glimmer should access paths in cases where it needs
* to. For instance, the `key` value of `{{each}}` loops.
*
* @param obj The object provided to get a value from
* @param path The path to get the value from
*/
let getPath;
/**
* Hook for specifying how Glimmer should update paths in cases where it needs
* to. For instance, when updating a template reference (e.g. 2-way-binding)
*
* @param obj The object provided to get a value from
* @param path The path to get the value from
*/
let setPath;
/**
* Hook to warn if a style binding string or value was not marked as trusted
* (e.g. HTMLSafe)
*/
let warnIfStyleNotTrusted;
/**
* Hook to customize assertion messages in the VM. Usages can be stripped out
* by using the @glimmer/vm-babel-plugins package.
*/
let assert;
function debugAssert(test, msg, options) {
}
/**
* Hook to customize deprecation messages in the VM. Usages can be stripped out
* by using the @glimmer/vm-babel-plugins package.
*/
let deprecate;
function setGlobalContext(context) {
scheduleRevalidate = context.scheduleRevalidate;
scheduleDestroy = context.scheduleDestroy;
scheduleDestroyed = context.scheduleDestroyed;
toIterator = context.toIterator;
toBool = context.toBool;
getProp = context.getProp;
setProp = context.setProp;
getPath = context.getPath;
setPath = context.setPath;
warnIfStyleNotTrusted = context.warnIfStyleNotTrusted;
assert = context.assert;
deprecate = context.deprecate;
}
let assertGlobalContextWasSet;
let testOverrideGlobalContext;
export { assert, assertGlobalContextWasSet, debugAssert, setGlobalContext as default, deprecate, getPath, getProp, scheduleDestroy, scheduleDestroyed, scheduleRevalidate, setPath, setProp, testOverrideGlobalContext, toBool, toIterator, warnIfStyleNotTrusted };