UNPKG

ember-source

Version:

A JavaScript framework for creating ambitious web applications

58 lines (51 loc) 2.01 kB
import { c as createComputeRef, b as isInvokableRef, u as updateRef, v as valueForRef } from './reference-BqOLhKFy.js'; import { f as reifyPositional, g as buildUntouchableThis, h as check, e as reifyNamed } from './arguments-CDkbOqTS.js'; import { j as setInternalHelperManager } from './api-DuLOZMO_.js'; function internalHelper(helper) { return setInternalHelperManager(helper, {}); } const array = internalHelper(({ positional }) => { return createComputeRef(() => reifyPositional(positional), null, 'array'); }); const context = buildUntouchableThis('`fn` helper'); const fn = internalHelper(({ positional }) => { let callbackRef = check(positional[0]); return createComputeRef(() => { return (...invocationArgs) => { let [fn, ...args] = reifyPositional(positional); assertCallbackIsFn(callbackRef); if (isInvokableRef(callbackRef)) { let value = args.length > 0 ? args[0] : invocationArgs[0]; return void updateRef(callbackRef, value); } else { // eslint-disable-next-line @typescript-eslint/no-unsafe-return -- @fixme return fn.call(context, ...args, ...invocationArgs); } }; }, null, 'fn'); }); function assertCallbackIsFn(callbackRef) { if (!(callbackRef && (isInvokableRef(callbackRef) || typeof valueForRef(callbackRef) === 'function'))) { throw new Error(`You must pass a function as the \`fn\` helper's first argument, you passed ${callbackRef ? valueForRef(callbackRef) : callbackRef}. While rendering:\n\n${callbackRef?.debugLabel}`); } } const hash = internalHelper(({ named }) => { let ref = createComputeRef(() => { return reifyNamed(named); }, null, 'hash'); // Setup the children so that templates can bypass getting the value of // the reference and treat children lazily let children = new Map(); for (let name in named) { children.set(name, named[name]); } ref.children = children; return ref; }); export { array as a, fn as f, hash as h, internalHelper as i };