• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript util.dict函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: debug

export function debug(c: DebugConstants, op: Op, ...operands: number[]): [string, object] {
  let metadata = METADATA[op];

  if (!metadata) {
    throw unreachable(`Missing Opcode Metadata for ${op}`);
  }

  let out = dict<Opaque>();

  metadata.ops.forEach((operand, index) => {
    let op = operands[index];

    switch (operand.type) {
      case 'i32':
      case 'symbol':
      case 'block':
        out[operand.name] = op;
        break;
      case 'handle':
        out[operand.name] = c.resolveHandle(op);
        break;
      case 'str':
        out[operand.name] = c.getString(op);
        break;
      case 'option-str':
        out[operand.name] = op ? c.getString(op) : null;
        break;
      case 'str-array':
        out[operand.name] = c.getStringArray(op);
        break;
      case 'array':
        out[operand.name] = c.getArray(op);
        break;
      case 'bool':
        out[operand.name] = !!op;
        break;
      case 'primitive':
        out[operand.name] = decodePrimitive(op, c);
        break;
      case 'register':
        out[operand.name] = Register[op];
        break;
      case 'table':
        out[operand.name] = c.getSymbolTable(op);
        break;
      case 'serializable':
        out[operand.name] = c.getSerializable(op);
        break;
      case 'lazy-constant':
        out[operand.name] = (c as Recast<DebugConstants, LazyDebugConstants>).getOther(op);
        break;
    }
  });

  return [metadata.name, out];
}
开发者ID:jayphelps,项目名称:glimmer,代码行数:56,代码来源:debug.ts


示例2: specifierFor

export function specifierFor(module: ModuleName, name: NamedExport): Specifier {
  let specifiers = SPECIFIERS[module];

  if (!specifiers) specifiers = SPECIFIERS[module] = dict<Specifier>();

  let specifier = specifiers[name];

  if (!specifier) specifier = specifiers[name] = { module, name };

  return specifier;
}
开发者ID:jayphelps,项目名称:glimmer,代码行数:11,代码来源:specifiers.ts


示例3: check

APPEND_OPCODES.add(Op.InvokePartial, (vm, { op1: _meta, op2: _symbols, op3: _evalInfo }) => {
  let { constants, constants: { resolver }, stack } = vm;

  let name = check(stack.pop(), CheckReference).value();
  assert(typeof name === 'string', `Could not find a partial named "${String(name)}"`);

  let meta = constants.getSerializable<TemplateMeta>(_meta);
  let outerSymbols = constants.getStringArray(_symbols);
  let evalInfo = constants.getArray(_evalInfo);

  let specifier = resolver.lookupPartial(name as string, meta);

  assert(specifier, `Could not find a partial named "${name}"`);

  let definition = resolver.resolve<PartialDefinition>(specifier!);

  let { symbolTable, handle } = definition.getPartial();

  {
    let partialSymbols = symbolTable.symbols;
    let outerScope = vm.scope();
    let partialScope = vm.pushRootScope(partialSymbols.length, false);
    partialScope.bindCallerScope(outerScope.getCallerScope());
    partialScope.bindEvalScope(outerScope.getEvalScope());
    partialScope.bindSelf(outerScope.getSelf());

    let locals = dict<VersionedPathReference<Opaque>>();

    for (let i = 0; i < evalInfo.length; i++) {
      let slot = evalInfo[i];
      let name = outerSymbols[slot - 1];
      let ref  = outerScope.getSymbol(slot);
      locals[name] = ref;
    }

    let evalScope = outerScope.getEvalScope()!;

    for (let i = 0; i < partialSymbols.length; i++) {
      let name = partialSymbols[i];
      let symbol = i + 1;
      let value = evalScope[name];

      if (value !== undefined) partialScope.bind(symbol, value);
    }

    partialScope.bindPartialMap(locals);

    vm.pushFrame(); // sp += 2
    vm.call(handle!);
  }

  expectStackChange(vm.stack, 1, 'InvokePartial');
});
开发者ID:jayphelps,项目名称:glimmer,代码行数:53,代码来源:partial.ts


示例4: forEach

import { Option, Dict, dict, HAS_NATIVE_WEAKMAP } from '@glimmer/util';

export const EMPTY_ARRAY: any[] = (HAS_NATIVE_WEAKMAP ? Object.freeze([]) : []) as any;
export const EMPTY_DICT: Dict<any> = HAS_NATIVE_WEAKMAP ? Object.freeze(dict<any>()) : dict<any>();

export interface EnumerableCallback<T> {
  (item: T): void;
}

export interface Enumerable<T> {
  forEach(callback: EnumerableCallback<T>): void;
}

export interface Destroyable {
  destroy(): void;
}

export interface Range<T> {
  min(): number;
  max(): number;
  at(index: number): Option<T>;
}

export class ListRange<T> implements Range<T> {
  private list: T[];

  // [start, end]
  private start: number;
  private end: number;

  constructor(list: T[], start: number, end: number) {
开发者ID:asakusuma,项目名称:glimmer,代码行数:31,代码来源:utils.ts


示例5: equalsElement

export function equalsElement(element: Element | null, tagName: string, attributes: Object, content: string) {
  if (element === null) {
    QUnit.assert.pushResult({
      result: false,
      actual: element,
      expected: true,
      message: `failed - expected element to not be null`
    });
    return;
  }

  QUnit.assert.pushResult({
    result: element.tagName === tagName.toUpperCase(),
    actual: element.tagName.toLowerCase(),
    expected: tagName,
    message: `expect tagName to be ${tagName}`
  });

  let expectedAttrs: Dict<Matcher> = dict<Matcher>();

  let expectedCount = 0;
  for (let prop in attributes) {
    expectedCount++;
    let expected = attributes[prop];

    let matcher: Matcher = typeof expected === 'object' && MATCHER in expected ? expected : equalsAttr(expected);
    expectedAttrs[prop] = matcher;

    QUnit.assert.pushResult({
      result: expectedAttrs[prop].match(element && element.getAttribute(prop)),
      actual: matcher.fail(element && element.getAttribute(prop)),
      expected: matcher.fail(element && element.getAttribute(prop)),
      message: `Expected element's ${prop} attribute ${matcher.expected()}`
    });
  }

  let actualAttributes = {};
  if (element) {
    for (let i = 0, l = element.attributes.length; i < l; i++) {
      actualAttributes[element.attributes[i].name] = element.attributes[i].value;
    }
  }

  if (!(element instanceof HTMLElement)) {
        QUnit.assert.pushResult({
          result: element instanceof HTMLElement,
          actual: null,
          expected: null,
          message: "Element must be an HTML Element, not an SVG Element"
        });
  } else {
    QUnit.assert.pushResult({
      result: element.attributes.length === expectedCount,
      actual: element.attributes.length,
      expected: expectedCount,
      message: `Expected ${expectedCount} attributes; got ${element.outerHTML}`
    });

    if (content !== null) {
      QUnit.assert.pushResult({
        result: element.innerHTML === content,
        actual: element.innerHTML,
        expected: content,
        message: `The element had '${content}' as its content`
      });
    }
  }
}
开发者ID:jayphelps,项目名称:glimmer,代码行数:68,代码来源:environment.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript util.unreachable函数代码示例发布时间:2022-05-28
下一篇:
TypeScript util.assert函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap