当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Meta.removeDescriptors方法代码示例

本文整理汇总了TypeScript中ember-meta.Meta.removeDescriptors方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Meta.removeDescriptors方法的具体用法?TypeScript Meta.removeDescriptors怎么用?TypeScript Meta.removeDescriptors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ember-meta.Meta的用法示例。


在下文中一共展示了Meta.removeDescriptors方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: defineProperty

export function defineProperty(
  obj: object,
  keyName: string,
  desc: Descriptor | undefined | null,
  data?: any | undefined | null,
  meta?: Meta
) {
  if (meta === undefined) {
    meta = metaFor(obj);
  }

  let watching = meta.peekWatching(keyName) > 0;
  let previousDesc = descriptorFor(obj, keyName, meta);
  let wasDescriptor = previousDesc !== undefined;

  if (wasDescriptor) {
    previousDesc.teardown(obj, keyName, meta);
    meta.removeDescriptors(keyName);
  }

  // used to track if the the property being defined be enumerable
  let enumerable = true;

  // Ember.NativeArray is a normal Ember.Mixin that we mix into `Array.prototype` when prototype extensions are enabled
  // mutating a native object prototype like this should _not_ result in enumerable properties being added (or we have significant
  // issues with things like deep equality checks from test frameworks, or things like jQuery.extend(true, [], [])).
  //
  // this is a hack, and we should stop mutating the array prototype by default 😫
  if (obj === Array.prototype) {
    enumerable = false;
  }

  let value;
  if (desc instanceof Descriptor) {
    value = desc;

    Object.defineProperty(obj, keyName, {
      configurable: true,
      enumerable,
      get: DESCRIPTOR_GETTER_FUNCTION(keyName, value),
    });

    meta.writeDescriptors(keyName, value);

    desc.setup(obj, keyName);
  } else if (desc === undefined || desc === null) {
    value = data;

    if (DEBUG && watching) {
      meta.writeValues(keyName, data);

      let defaultDescriptor = {
        configurable: true,
        enumerable,
        set: MANDATORY_SETTER_FUNCTION(keyName),
        get: DEFAULT_GETTER_FUNCTION(keyName),
      };

      Object.defineProperty(obj, keyName, defaultDescriptor);
    } else if (wasDescriptor || enumerable === false) {
      Object.defineProperty(obj, keyName, {
        configurable: true,
        enumerable,
        writable: true,
        value,
      });
    } else {
      obj[keyName] = data;
    }
  } else {
    value = desc;

    // fallback to ES5
    Object.defineProperty(obj, keyName, desc);
  }

  // if key is being watched, override chains that
  // were initialized with the prototype
  if (watching) {
    overrideChains(obj, keyName, meta);
  }

  // The `value` passed to the `didDefineProperty` hook is
  // either the descriptor or data, whichever was passed.
  if (typeof (obj as ExtendedObject).didDefineProperty === 'function') {
    (obj as ExtendedObject).didDefineProperty!(obj, keyName, value);
  }
}
开发者ID:chundabear,项目名称:ember.js,代码行数:88,代码来源:properties.ts


注:本文中的ember-meta.Meta.removeDescriptors方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。