當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript meta.descriptorFor函數代碼示例

本文整理匯總了TypeScript中@ember/-internals/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/object
  @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}
  @since 3.1.0
  @public
*/
function notifyPropertyChange(obj: object, keyName: string, _meta?: Meta | null): void {
  let meta = _meta === undefined ? peekMeta(obj) : _meta;

  if (meta !== null && (meta.isInitializing() || meta.isPrototypeMeta(obj))) {
    return;
  }

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

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

  if (meta !== null && 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 (meta !== null) {
    if (meta.isSourceDestroying()) {
      return;
    }
    markObjectAsDirty(obj, keyName, meta);
  }

  if (DEBUG) {
    assertNotRendered(obj, keyName);
  }
}
開發者ID:kategengler,項目名稱:ember.js,代碼行數:51,代碼來源:property_events.ts

示例2: get

export function get(obj: object, keyName: string): any {
  assert(
    `Get must be called with two arguments; an object and a property key`,
    arguments.length === 2
  );
  assert(
    `Cannot call get with '${keyName}' on an undefined object.`,
    obj !== undefined && obj !== null
  );
  assert(
    `The key provided to get must be a string or number, you passed ${keyName}`,
    typeof keyName === 'string' || (typeof keyName === 'number' && !isNaN(keyName))
  );
  assert(
    `'this' in paths is not supported`,
    typeof keyName !== 'string' || keyName.lastIndexOf('this.', 0) !== 0
  );

  let type = typeof obj;

  let isObject = type === 'object';
  let isFunction = type === 'function';
  let isObjectLike = isObject || isFunction;

  let value: any;

  if (isObjectLike) {
    if (EMBER_METAL_TRACKED_PROPERTIES) {
      let tracker = getCurrentTracker();
      if (tracker) tracker.add(tagForProperty(obj, keyName));
    }

    let descriptor = descriptorFor(obj, keyName);
    if (descriptor !== undefined) {
      return descriptor.get(obj, keyName);
    }

    if (DEBUG && HAS_NATIVE_PROXY) {
      value = getPossibleMandatoryProxyValue(obj, keyName);
    } else {
      value = obj[keyName];
    }
  } else {
    value = obj[keyName];
  }

  if (value === undefined) {
    if (isPath(keyName)) {
      return _getPath(obj, keyName);
    }
    if (
      isObject &&
      !(keyName in obj) &&
      typeof (obj as MaybeHasUnknownProperty).unknownProperty === 'function'
    ) {
      return (obj as MaybeHasUnknownProperty).unknownProperty!(keyName);
    }
  }
  return value;
}
開發者ID:Turbo87,項目名稱:ember.js,代碼行數:60,代碼來源:property_get.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:Turbo87,項目名稱: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:kategengler,項目名稱:ember.js,代碼行數:9,代碼來源:property_events.ts

示例5: applyMixin

export function applyMixin(obj: { [key: string]: any }, mixins: Mixin[]) {
  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 = followMethodAlias(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);
    }

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

  return obj;
}
開發者ID:Turbo87,項目名稱:ember.js,代碼行數:48,代碼來源:mixin.ts

示例6: 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:GreatWizard,項目名稱:ember.js,代碼行數:19,代碼來源:injected_property.ts

示例7: 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:Turbo87,項目名稱:ember.js,代碼行數:41,代碼來源:mixin.ts

示例8: followMethodAlias

function followMethodAlias(
  obj: object,
  _desc: Alias,
  descs: { [key: string]: any },
  values: { [key: string]: any }
) {
  let altKey = _desc.methodName;
  let possibleDesc;
  let desc = descs[altKey];
  let value = values[altKey];

  if (desc !== undefined || value !== undefined) {
  } else if ((possibleDesc = descriptorFor(obj, altKey)) !== undefined) {
    desc = possibleDesc;
    value = undefined;
  } else {
    desc = undefined;
    value = obj[altKey];
  }

  return { desc, value };
}
開發者ID:Turbo87,項目名稱:ember.js,代碼行數:22,代碼來源:mixin.ts

示例9: watchKey

export function watchKey(obj: object, keyName: string, _meta?: Meta): void {
  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:kategengler,項目名稱:ember.js,代碼行數:23,代碼來源:watch_key.ts

示例10: get

export function get(obj: object, keyName: string): any {
  assert(
    `Get must be called with two arguments; an object and a property key`,
    arguments.length === 2
  );
  assert(
    `Cannot call get with '${keyName}' on an undefined object.`,
    obj !== undefined && obj !== null
  );
  assert(
    `The key provided to get must be a string or number, you passed ${keyName}`,
    typeof keyName === 'string' || (typeof keyName === 'number' && !isNaN(keyName))
  );
  assert(
    `'this' in paths is not supported`,
    typeof keyName !== 'string' || keyName.lastIndexOf('this.', 0) !== 0
  );

  let type = typeof obj;

  let isObject = type === 'object';
  let isFunction = type === 'function';
  let isObjectLike = isObject || isFunction;

  let descriptor;
  let value: any;

  if (isObjectLike) {
    if (EMBER_METAL_TRACKED_PROPERTIES) {
      let tracker = getCurrentTracker();
      if (tracker) tracker.add(tagForProperty(obj, keyName));
    }

    descriptor = descriptorFor(obj, keyName);
    if (descriptor !== undefined) {
      return descriptor.get(obj, keyName);
    }

    if (DEBUG && HAS_NATIVE_PROXY) {
      value = getPossibleMandatoryProxyValue(obj, keyName);
    } else {
      value = obj[keyName];
    }

    if (PROPERTY_BASED_DESCRIPTORS && isDescriptor(value)) {
      deprecate(
        `[DEPRECATED] computed property '${keyName}' was not set on object '${toString(
          obj
        )}' via 'defineProperty'`,
        false,
        {
          id: '@ember/-internals/meta.descriptor-on-object',
          until: '3.5.0',
          url:
            'https://emberjs.com/deprecations/v3.x#toc_use-defineProperty-to-define-computed-properties',
        }
      );

      Object.defineProperty(obj, keyName, {
        configurable: true,
        enumerable: value.enumerable === false,
        get() {
          return value.get(this, keyName);
        },
      });

      meta(obj).writeDescriptors(keyName, value);

      value.setup(obj, keyName);

      return value.get(obj, keyName);
    }
  } else {
    value = obj[keyName];
  }

  if (value === undefined) {
    if (isPath(keyName)) {
      return _getPath(obj, keyName);
    }
    if (
      isObject &&
      !(keyName in obj) &&
      typeof (obj as MaybeHasUnknownProperty).unknownProperty === 'function'
    ) {
      return (obj as MaybeHasUnknownProperty).unknownProperty!(keyName);
    }
  }
  return value;
}
開發者ID:knownasilya,項目名稱:ember.js,代碼行數:90,代碼來源:property_get.ts


注:本文中的@ember/-internals/meta.descriptorFor函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。