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


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

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


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

示例1: 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

示例2: setup

 setup(obj: object, keyName: string): void {
   assert(`Setting alias '${keyName}' on self`, this.altKey !== keyName);
   let meta = metaFor(obj);
   if (meta.peekWatching(keyName)) {
     addDependentKeys(this, obj, keyName, meta);
   }
 }
开发者ID:Artmann,项目名称:ember.js,代码行数:7,代码来源:alias.ts

示例3: _set

  _set(obj: object, keyName: string, value: any) {
    let cache = getCacheFor(obj);
    let hadCachedValue = cache.has(keyName);
    let cachedValue = cache.get(keyName);

    let ret = this._setter!.call(obj, keyName, value, cachedValue);

    // allows setter to return the same value that is cached already
    if (hadCachedValue && cachedValue === ret) {
      return ret;
    }

    let meta = metaFor(obj);
    if (!hadCachedValue) {
      addDependentKeys(this, obj, keyName, meta);
    }

    cache.set(keyName, ret);

    notifyPropertyChange(obj, keyName, meta);

    if (EMBER_METAL_TRACKED_PROPERTIES) {
      let propertyTag = tagForProperty(obj, keyName);
      setLastRevisionFor(obj, keyName, propertyTag.value());
    }

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

示例4: addListener

export function addListener(
  obj: object,
  eventName: string,
  target: object | Function | null,
  method?: Function | string,
  once?: boolean
) {
  assert('You must pass at least an object and event name to addListener', !!obj && !!eventName);

  if (DID_INIT_ATTRS && ENV._ENABLE_DID_INIT_ATTRS_SUPPORT === true) {
    deprecate(
      `didInitAttrs called in ${obj && obj.toString && obj.toString()}.`,
      eventName !== 'didInitAttrs',
      {
        id: 'ember-views.did-init-attrs',
        until: '3.0.0',
        url: 'https://emberjs.com/deprecations/v2.x#toc_ember-component-didinitattrs',
      }
    );
  } else {
    assert(
      `didInitAttrs called in ${obj && obj.toString && obj.toString()} is no longer supported.`,
      eventName !== 'didInitAttrs'
    );
  }

  if (!method && 'function' === typeof target) {
    method = target;
    target = null;
  }

  metaFor(obj).addToListeners(eventName, target, method!, once === true);
}
开发者ID:Artmann,项目名称:ember.js,代码行数:33,代码来源:events.ts

示例5: get

  get(obj: object, keyName: string) {
    if (this._volatile) {
      return this._getter.call(obj, keyName);
    }

    let cache = getCacheFor(obj);
    let propertyTag;

    if (EMBER_METAL_TRACKED_PROPERTIES) {
      propertyTag = tagForProperty(obj, keyName);

      if (cache.has(keyName)) {
        // special-case for computed with no dependent keys used to
        // trigger cacheable behavior.
        if (!this._auto && (!this._dependentKeys || this._dependentKeys.length === 0)) {
          return cache.get(keyName);
        }

        let lastRevision = getLastRevisionFor(obj, keyName);
        if (propertyTag.validate(lastRevision)) {
          return cache.get(keyName);
        }
      }
    } else {
      if (cache.has(keyName)) {
        return cache.get(keyName);
      }
    }

    let parent: any;
    let tracker: any;

    if (EMBER_METAL_TRACKED_PROPERTIES) {
      parent = getCurrentTracker();
      tracker = setCurrentTracker();
    }

    let ret = this._getter.call(obj, keyName);

    if (EMBER_METAL_TRACKED_PROPERTIES) {
      setCurrentTracker(parent!);
      let tag = tracker!.combine();
      if (parent) parent.add(tag);

      update(propertyTag as any, tag);
      setLastRevisionFor(obj, keyName, (propertyTag as any).value());
    }

    cache.set(keyName, ret);

    let meta = metaFor(obj);
    let chainWatchers = meta.readableChainWatchers();
    if (chainWatchers !== undefined) {
      chainWatchers.revalidate(keyName);
    }
    addDependentKeys(this, obj, keyName, meta);

    return ret;
  }
开发者ID:chundabear,项目名称:ember.js,代码行数:59,代码来源:computed.ts

示例6: tagFor

export function tagFor(object: any | null, _meta?: Meta): Tag {
  if (typeof object === 'object' && object !== null) {
    let meta = _meta === undefined ? metaFor(object) : _meta;
    return meta.writableTag(makeTag);
  } else {
    return CONSTANT_TAG;
  }
}
开发者ID:Artmann,项目名称:ember.js,代码行数:8,代码来源:tags.ts

示例7: watchPath

export function watchPath(obj: any, keyPath: string, meta?: Meta): void {
  let m = meta === undefined ? metaFor(obj) : meta;
  let counter = m.peekWatching(keyPath) || 0;

  m.writeWatching(keyPath, counter + 1);
  if (counter === 0) {
    // activate watching first time
    m.writableChains(makeChainNode).add(keyPath);
  }
}
开发者ID:Artmann,项目名称:ember.js,代码行数:10,代码来源:watch_path.ts

示例8: get

 get(obj: object, keyName: string) {
   let ret = get(obj, this.altKey);
   let cache = getCacheFor(obj);
   if (cache.get(keyName) !== CONSUMED) {
     let meta = metaFor(obj);
     cache.set(keyName, CONSUMED);
     addDependentKeys(this, obj, keyName, meta);
   }
   return ret;
 }
开发者ID:Artmann,项目名称:ember.js,代码行数:10,代码来源:alias.ts

示例9: removeListener

export function removeListener(
  obj: object,
  eventName: string,
  target: object | null,
  method?: Function | string
) {
  assert('You must pass at least an object and event name to removeListener', !!obj && !!eventName);

  if (!method && 'function' === typeof target) {
    method = target;
    target = null;
  }

  metaFor(obj).removeFromListeners(eventName, target, method!);
}
开发者ID:Artmann,项目名称:ember.js,代码行数:15,代码来源:events.ts

示例10: removeChainWatcher

function removeChainWatcher(obj: object, keyName: string, node: ChainNode, _meta?: Meta): void {
  if (!isObject(obj)) {
    return;
  }

  let meta = _meta === undefined ? peekMeta(obj) : _meta;

  if (
    meta === undefined ||
    meta.isSourceDestroying() ||
    meta.isMetaDestroyed() ||
    meta.readableChainWatchers() === undefined
  ) {
    return;
  }

  // make meta writable
  meta = metaFor(obj);

  meta.readableChainWatchers().remove(keyName, node);

  unwatchKey(obj, keyName, meta);
}
开发者ID:realityendshere,项目名称:ember.js,代码行数:23,代码来源:chains.ts


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