ember-source
Version:
A JavaScript framework for creating ambitious web applications
68 lines (63 loc) • 2.62 kB
JavaScript
import { isDestroying, isDestroyed, associateDestroyableChild } from '../@glimmer/destroyable/index.js';
import { g as getInternalHelperManager, h as hasValue, a as hasDestroyable } from './api-BqXkkT0p.js';
import '../@glimmer/global-context/index.js';
import './debug-to-string-CFb7h0lY.js';
import { createCache, getValue } from '../@glimmer/validator/index.js';
import './reference-C3TKDRnP.js';
import './capabilities-O_xc7Yqk.js';
import { getOwner } from '../@glimmer/owner/index.js';
import { E as EMPTY_ARGS, d as EMPTY_NAMED, e as EMPTY_POSITIONAL } from './dynamic-CFg3dljk.js';
let ARGS_CACHES = new WeakMap() ;
function getArgs(proxy) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- @fixme
return getValue(ARGS_CACHES.get(proxy) );
}
class SimpleArgsProxy {
argsCache;
constructor(context, computeArgs = () => EMPTY_ARGS) {
let argsCache = createCache(() => computeArgs(context));
{
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- @fixme
ARGS_CACHES.set(this, argsCache);
Object.freeze(this);
}
}
get named() {
return getArgs(this).named || EMPTY_NAMED;
}
get positional() {
return getArgs(this).positional || EMPTY_POSITIONAL;
}
}
////////////
function invokeHelper(context, definition, computeArgs) {
if ((typeof context !== 'object' || context === null)) {
throw new Error(`Expected a context object to be passed as the first parameter to invokeHelper, got ${context}`);
}
const owner = getOwner(context);
const internalManager = getInternalHelperManager(definition);
if (typeof internalManager === 'function') {
throw new Error('Found a helper manager, but it was an internal built-in helper manager. `invokeHelper` does not support internal helpers yet.');
}
const manager = internalManager.getDelegateFor(owner);
let args = new SimpleArgsProxy(context, computeArgs);
let bucket = manager.createHelper(definition, args);
let cache;
if (hasValue(manager)) {
cache = createCache(() => {
if ((isDestroying(cache) || isDestroyed(cache))) {
throw new Error(`You attempted to get the value of a helper after the helper was destroyed, which is not allowed`);
}
return manager.getValue(bucket);
});
associateDestroyableChild(context, cache);
} else {
throw new Error('TODO: unreachable, to be implemented with hasScheduledEffect');
}
if (hasDestroyable(manager)) {
let destroyable = manager.getDestroyable(bucket);
associateDestroyableChild(cache, destroyable);
}
return cache;
}
export { invokeHelper as i };