UNPKG

ember-source

Version:

A JavaScript framework for creating ambitious web applications

90 lines (83 loc) 3 kB
import { meta } from '../../../meta/lib/meta.js'; import Mixin from '../../../../object/mixin.js'; import { d as defineProperty, c as computed } from '../../../../../shared-chunks/namespace_search-Aog9nySA.js'; import '../../../environment/index.js'; import { updateTag as UPDATE_TAG, tagMetaFor, tagFor, combine } from '../../../../../@glimmer/validator/index.js'; import { i as isObject } from '../../../../../shared-chunks/super-Cm_a_cLQ.js'; import { s as setProxy } from '../../../../../shared-chunks/is_proxy-Cr1qlMv_.js'; import { g as get, t as tagForObject, a as tagForProperty } from '../../../../../shared-chunks/observers-R1ZklwWy.js'; import { s as set } from '../../../../../shared-chunks/property_set-O080KTKZ.js'; import '../../../../../shared-chunks/reference-BNqcwZWH.js'; import { s as setCustomTagFor } from '../../../../../shared-chunks/args-proxy-Dl0A0YWI.js'; import '../../../../../shared-chunks/capabilities-DGmQ_mz4.js'; /** @module ember */ function contentFor(proxy) { let content = get(proxy, 'content'); // SAFETY: Ideally we'd assert instead of casting, but @glimmer/validator doesn't give us // sufficient public types for this. Previously this code was .js and worked correctly so // hopefully this is sufficiently reliable. UPDATE_TAG(tagForObject(proxy), tagForObject(content)); return content; } function customTagForProxy(proxy, key, addMandatorySetter) { let meta = tagMetaFor(proxy); let tag = tagFor(proxy, key, meta); if (key in proxy) { return tag; } else { let tags = [tag, tagFor(proxy, 'content', meta)]; let content = contentFor(proxy); if (isObject(content)) { tags.push(tagForProperty(content, key, addMandatorySetter)); } return combine(tags); } } /** `ProxyMixin` forwards all properties not defined by the proxy itself to a proxied `content` object. See ObjectProxy for more details. @class ProxyMixin @namespace Ember @private */ const ProxyMixin = Mixin.create({ /** The object whose properties will be forwarded. @property content @type {unknown} @default null @public */ content: null, init() { this._super(...arguments); setProxy(this); tagForObject(this); setCustomTagFor(this, customTagForProxy); }, willDestroy() { this.set('content', null); this._super(...arguments); }, isTruthy: computed('content', function () { return Boolean(get(this, 'content')); }), unknownProperty(key) { let content = contentFor(this); return content ? get(content, key) : undefined; }, setUnknownProperty(key, value) { let m = meta(this); if (m.isInitializing() || m.isPrototypeMeta(this)) { // if marked as prototype or object is initializing then just // defineProperty rather than delegate defineProperty(this, key, null, value); return value; } let content = contentFor(this); return set(content, key, value); } }); export { contentFor, ProxyMixin as default };