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


TypeScript ember-meta.descriptorFor函数代码示例

本文整理汇总了TypeScript中ember-meta.descriptorFor函数的典型用法代码示例。如果您正苦于以下问题:TypeScript descriptorFor函数的具体用法?TypeScript descriptorFor怎么用?TypeScript descriptorFor使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: key

/**
  This function is called just after an object property has changed.
  It will notify any observers and clear caches among other things.

  Normally you will not need to call this method directly but if for some
  reason you can't directly watch a property you can invoke this method
  manually.

  @method notifyPropertyChange
  @for Ember
  @param {Object} obj The object with the property that will change
  @param {String} keyName The property key (or path) that will change.
  @param {Meta} meta The objects meta.
  @return {void}
  @private
*/
function notifyPropertyChange(obj: object, keyName: string, _meta?: Meta): void {
  let meta = _meta === undefined ? peekMeta(obj) : _meta;
  let hasMeta = meta !== undefined;

  if (hasMeta && !meta.isInitialized(obj)) {
    return;
  }

  let possibleDesc = descriptorFor(obj, keyName, meta);

  if (possibleDesc !== undefined && typeof possibleDesc.didChange === 'function') {
    possibleDesc.didChange(obj, keyName);
  }

  if (hasMeta && meta.peekWatching(keyName) > 0) {
    dependentKeysDidChange(obj, keyName, meta);
    chainsDidChange(obj, keyName, meta);
    notifyObservers(obj, keyName, meta);
  }

  if (PROPERTY_DID_CHANGE in obj) {
    obj[PROPERTY_DID_CHANGE](keyName);
  }

  if (hasMeta) {
    if (meta.isSourceDestroying()) {
      return;
    }
    markObjectAsDirty(obj, keyName, meta);
  }

  if (DEBUG) {
    assertNotRendered(obj, keyName);
  }
}
开发者ID:chundabear,项目名称:ember.js,代码行数:51,代码来源:property_events.ts

示例2: applyMixin

function applyMixin(obj: { [key: string]: any }, mixins: Mixin[], partial: boolean) {
  let descs = {};
  let values = {};
  let meta = metaFor(obj);
  let keys: string[] = [];
  let key, value, desc;

  (obj as any)._super = ROOT;

  // Go through all mixins and hashes passed in, and:
  //
  // * Handle concatenated properties
  // * Handle merged properties
  // * Set up _super wrapping if necessary
  // * Set up computed property descriptors
  // * Copying `toString` in broken browsers
  mergeMixins(mixins, meta, descs, values, obj, keys);

  for (let i = 0; i < keys.length; i++) {
    key = keys[i];
    if (key === 'constructor' || !values.hasOwnProperty(key)) {
      continue;
    }

    desc = descs[key];
    value = values[key];

    while (desc && desc instanceof Alias) {
      let followed = followAlias(obj, desc, descs, values);
      desc = followed.desc;
      value = followed.value;
    }

    if (desc === undefined && value === undefined) {
      continue;
    }

    if (descriptorFor(obj, key) !== undefined) {
      replaceObserversAndListeners(obj, key, null, value);
    } else {
      replaceObserversAndListeners(obj, key, obj[key], value);
    }

    if (
      ENV._ENABLE_BINDING_SUPPORT &&
      typeof Mixin.detectBinding === 'function' &&
      Mixin.detectBinding(key)
    ) {
      meta.writeBindings(key, value);
    }

    defineProperty(obj, key, desc, value, meta);
  }

  if (ENV._ENABLE_BINDING_SUPPORT && !partial && typeof Mixin.finishPartial === 'function') {
    Mixin.finishPartial(obj, meta);
  }

  return obj;
}
开发者ID:realityendshere,项目名称:ember.js,代码行数:60,代码来源:mixin.ts

示例3: giveMethodSuper

function giveMethodSuper(
  obj: object,
  key: string,
  method: Function,
  values: { [key: string]: any },
  descs: { [key: string]: any }
) {
  // Methods overwrite computed properties, and do not call super to them.
  if (descs[key] !== undefined) {
    return method;
  }

  // Find the original method in a parent mixin
  let superMethod = values[key];

  // If we didn't find the original value in a parent mixin, find it in
  // the original object
  if (superMethod === undefined && descriptorFor(obj, key) === undefined) {
    superMethod = obj[key];
  }

  // Only wrap the new method if the original method was a function
  if (typeof superMethod === 'function') {
    return wrap(method, superMethod);
  }

  return method;
}
开发者ID:realityendshere,项目名称:ember.js,代码行数:28,代码来源:mixin.ts

示例4: descriptorFor

  meta.forEachInDeps(depKey, (key: string) => {
    possibleDesc = descriptorFor(obj, key, meta);

    if (possibleDesc !== undefined && possibleDesc._suspended === obj) {
      return;
    }

    method(obj, key, meta);
  });
开发者ID:chundabear,项目名称:ember.js,代码行数:9,代码来源:property_events.ts

示例5: injectedPropertyGet

function injectedPropertyGet(this: any, keyName: string): any {
  let desc = descriptorFor(this, keyName);
  let owner = getOwner(this) || this.container; // fallback to `container` for backwards compat

  assert(
    `InjectedProperties should be defined with the inject computed property macros.`,
    desc && desc.type
  );
  assert(
    `Attempting to lookup an injected property on an object without a container, ensure that the object was instantiated via a container.`,
    !!owner
  );

  let specifier = `${desc.type}:${desc.name || keyName}`;
  return owner.lookup(specifier, {
    source: desc.source,
    namespace: desc.namespace,
  });
}
开发者ID:Artmann,项目名称:ember.js,代码行数:19,代码来源:injected_property.ts

示例6: giveDescriptorSuper

function giveDescriptorSuper(
  meta: Meta,
  key: string,
  property: ComputedProperty,
  values: { [key: string]: any },
  descs: { [key: string]: any },
  base: object
): ComputedProperty {
  let superProperty;

  // Computed properties override methods, and do not call super to them
  if (values[key] === undefined) {
    // Find the original descriptor in a parent mixin
    superProperty = descs[key];
  }

  // If we didn't find the original descriptor in a parent mixin, find
  // it on the original object.
  if (!superProperty) {
    superProperty = descriptorFor(base, key, meta);
  }

  if (superProperty === undefined || !(superProperty instanceof ComputedProperty)) {
    return property;
  }

  // Since multiple mixins may inherit from the same parent, we need
  // to clone the computed property so that other mixins do not receive
  // the wrapped version.
  property = Object.create(property);
  property._getter = wrap(property._getter, superProperty._getter) as ComputedPropertyGetter;
  if (superProperty._setter) {
    if (property._setter) {
      property._setter = wrap(property._setter, superProperty._setter) as ComputedPropertySetter;
    } else {
      property._setter = superProperty._setter;
    }
  }

  return property;
}
开发者ID:realityendshere,项目名称:ember.js,代码行数:41,代码来源:mixin.ts

示例7: followAlias

function followAlias(
  obj: object,
  desc: any,
  descs: { [key: string]: any },
  values: { [key: string]: any }
) {
  let altKey = desc.methodName;
  let value;
  let possibleDesc;
  if (descs[altKey] || values[altKey]) {
    value = values[altKey];
    desc = descs[altKey];
  } else if ((possibleDesc = descriptorFor(obj, altKey)) !== undefined) {
    desc = possibleDesc;
    value = undefined;
  } else {
    desc = undefined;
    value = obj[altKey];
  }

  return { desc, value };
}
开发者ID:realityendshere,项目名称:ember.js,代码行数:22,代码来源:mixin.ts

示例8: watchKey

export function watchKey(obj: object, keyName: string, _meta?: Meta) {
  let meta = _meta === undefined ? metaFor(obj) : _meta;
  let count = meta.peekWatching(keyName);
  meta.writeWatching(keyName, count + 1);

  if (count === 0) {
    // activate watching first time
    let possibleDesc = descriptorFor(obj, keyName, meta);

    if (possibleDesc !== undefined && possibleDesc.willWatch !== undefined) {
      possibleDesc.willWatch(obj, keyName, meta);
    }

    if (typeof (obj as MaybeHasWillWatchProperty).willWatchProperty === 'function') {
      (obj as MaybeHasWillWatchProperty).willWatchProperty!(keyName);
    }

    if (DEBUG) {
      // NOTE: this is dropped for prod + minified builds
      handleMandatorySetter(meta, obj, keyName);
    }
  }
}
开发者ID:chundabear,项目名称:ember.js,代码行数:23,代码来源:watch_key.ts

示例9: unwatchKey

export function unwatchKey(obj: object, keyName: string, _meta?: Meta) {
  let meta = _meta === undefined ? peekMeta(obj) : _meta;

  // do nothing of this object has already been destroyed
  if (meta === undefined || meta.isSourceDestroyed()) {
    return;
  }

  let count = meta.peekWatching(keyName);
  if (count === 1) {
    meta.writeWatching(keyName, 0);

    let possibleDesc = descriptorFor(obj, keyName, meta);
    let isDescriptor = possibleDesc !== undefined;

    if (isDescriptor && possibleDesc.didUnwatch !== undefined) {
      possibleDesc.didUnwatch(obj, keyName, meta);
    }

    if (typeof (obj as MaybeHasDidUnwatchProperty).didUnwatchProperty === 'function') {
      (obj as MaybeHasDidUnwatchProperty).didUnwatchProperty!(keyName);
    }

    if (DEBUG) {
      // It is true, the following code looks quite WAT. But have no fear, It
      // exists purely to improve development ergonomics and is removed from
      // ember.min.js and ember.prod.js builds.
      //
      // Some further context: Once a property is watched by ember, bypassing `set`
      // for mutation, will bypass observation. This code exists to assert when
      // that occurs, and attempt to provide more helpful feedback. The alternative
      // is tricky to debug partially observable properties.
      if (!isDescriptor && keyName in obj) {
        let maybeMandatoryDescriptor = lookupDescriptor(obj, keyName);

        if (
          maybeMandatoryDescriptor &&
          maybeMandatoryDescriptor.set &&
          (maybeMandatoryDescriptor.set as MandatorySetterFunction).isMandatorySetter
        ) {
          if (
            maybeMandatoryDescriptor.get &&
            (maybeMandatoryDescriptor.get as InheritingGetterFunction).isInheritingGetter
          ) {
            let possibleValue = meta.readInheritedValue('values', keyName);
            if (possibleValue === UNDEFINED) {
              delete obj[keyName];
              return;
            }
          }

          Object.defineProperty(obj, keyName, {
            configurable: true,
            enumerable: Object.prototype.propertyIsEnumerable.call(obj, keyName),
            writable: true,
            value: meta.peekValues(keyName),
          });
          meta.deleteFromValues(keyName);
        }
      }
    }
  } else if (count > 1) {
    meta.writeWatching(keyName, count - 1);
  }
}
开发者ID:chundabear,项目名称:ember.js,代码行数:65,代码来源:watch_key.ts

示例10: 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.descriptorFor函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。