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


TypeScript jit.IAttributeParser类代码示例

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


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

示例1: bindLetElement

  private bindLetElement(parentManifest: IElementSymbol, node: HTMLElement): void {
    const symbol = new LetElementSymbol(this.dom, node);
    parentManifest.childNodes.push(symbol);

    const attributes = node.attributes;
    let i = 0;
    while (i < attributes.length) {
      const attr = attributes[i];
      if (attr.name === 'to-view-model') {
        node.removeAttribute('to-view-model');
        symbol.toViewModel = true;
        continue;
      }
      const attrSyntax = this.attrParser.parse(attr.name, attr.value);
      const command = this.resources.getBindingCommand(attrSyntax);
      const bindingType = command === null ? BindingType.Interpolation : command.bindingType;
      const expr = this.exprParser.parse(attrSyntax.rawValue, bindingType);
      const to = PLATFORM.camelCase(attrSyntax.target);
      const info = new BindableInfo(to, BindingMode.toView);
      symbol.bindings.push(new BindingSymbol(command, info, expr, attrSyntax.rawValue, to));

      ++i;
    }
    node.parentNode.replaceChild(symbol.marker as Node, node);
  }
开发者ID:aurelia,项目名称:aurelia,代码行数:25,代码来源:template-binder.ts

示例2: bind

  public bind(node: HTMLTemplateElement): PlainElementSymbol {
    if (Tracer.enabled) { Tracer.enter('TemplateBinder', 'bind', slice.call(arguments)); }
    if (Profiler.enabled) { enter(); }

    const surrogateSave = this.surrogate;
    const parentManifestRootSave = this.parentManifestRoot;
    const manifestRootSave = this.manifestRoot;
    const manifestSave = this.manifest;

    const manifest = this.surrogate = this.manifest = new PlainElementSymbol(node);

    const attributes = node.attributes;
    let i = 0;
    while (i < attributes.length) {
      const attr = attributes[i];
      const attrSyntax = this.attrParser.parse(attr.name, attr.value);

      if (invalidSurrogateAttribute[attrSyntax.target] === true) {
        if (Profiler.enabled) { leave(); }
        throw new Error(`Invalid surrogate attribute: ${attrSyntax.target}`);
        // TODO: use reporter
      }
      const attrInfo = this.resources.getAttributeInfo(attrSyntax);
      if (attrInfo === null) {
        this.bindPlainAttribute(attrSyntax, attr);
      } else if (attrInfo.isTemplateController) {
        if (Profiler.enabled) { leave(); }
        throw new Error('Cannot have template controller on surrogate element.');
        // TODO: use reporter
      } else {
        this.bindCustomAttribute(attrSyntax, attrInfo);
      }
      ++i;
    }

    this.bindChildNodes(node);

    this.surrogate = surrogateSave;
    this.parentManifestRoot = parentManifestRootSave;
    this.manifestRoot = manifestRootSave;
    this.manifest = manifestSave;

    if (Profiler.enabled) { leave(); }
    if (Tracer.enabled) { Tracer.leave(); }
    return manifest;
  }
开发者ID:aurelia,项目名称:aurelia,代码行数:46,代码来源:template-binder.ts

示例3: bindMultiAttribute

  private bindMultiAttribute(symbol: IResourceAttributeSymbol, attrInfo: AttrInfo, value: string): void {
    if (Tracer.enabled) { Tracer.enter('TemplateBinder', 'bindMultiAttribute', slice.call(arguments)); }

    const attributes = parseMultiAttributeBinding(value);
    let attr: IAttrLike;
    for (let i = 0, ii = attributes.length; i < ii; ++i) {
      attr = attributes[i];
      const attrSyntax = this.attrParser.parse(attr.name, attr.value);
      const command = this.resources.getBindingCommand(attrSyntax);
      const bindingType = command === null ? BindingType.Interpolation : command.bindingType;
      const expr = this.exprParser.parse(attrSyntax.rawValue, bindingType);
      let bindable = attrInfo.bindables[attrSyntax.target];
      if (bindable === undefined) {
        // everything in a dynamicOptions expression must be used, so if it's not a bindable then we create one on the spot
        bindable = attrInfo.bindables[attrSyntax.target] = new BindableInfo(attrSyntax.target, BindingMode.toView);
      }

      symbol.bindings.push(new BindingSymbol(command, bindable, expr, attrSyntax.rawValue, attrSyntax.target));
    }

    if (Tracer.enabled) { Tracer.leave(); }
  }
开发者ID:aurelia,项目名称:aurelia,代码行数:22,代码来源:template-binder.ts

示例4: bindAttributes

  private bindAttributes(node: HTMLTemplateElement | HTMLElement, parentManifest: IElementSymbol): void {
    if (Tracer.enabled) { Tracer.enter('TemplateBinder', 'bindAttributes', slice.call(arguments)); }

    const { parentManifestRoot, manifestRoot, manifest } = this;
    // This is the top-level symbol for the current depth.
    // If there are no template controllers or replace-parts, it is always the manifest itself.
    // If there are template controllers, then this will be the outer-most TemplateControllerSymbol.
    let manifestProxy: IParentNodeSymbol = manifest;

    const replacePart = this.declareReplacePart(node);

    let previousController: TemplateControllerSymbol;
    let currentController: TemplateControllerSymbol;

    const attributes = node.attributes;
    let i = 0;
    while (i < attributes.length) {
      const attr = attributes[i];
      ++i;
      if (attributesToIgnore[attr.name] === true) {
        continue;
      }
      const attrSyntax = this.attrParser.parse(attr.name, attr.value);
      const attrInfo = this.resources.getAttributeInfo(attrSyntax);

      if (attrInfo === null) {
        // it's not a custom attribute but might be a regular bound attribute or interpolation (it might also be nothing)
        this.bindPlainAttribute(attrSyntax, attr);
      } else if (attrInfo.isTemplateController) {
        // the manifest is wrapped by the inner-most template controller (if there are multiple on the same element)
        // so keep setting manifest.templateController to the latest template controller we find
        currentController = manifest.templateController = this.declareTemplateController(attrSyntax, attrInfo);

        // the proxy and the manifest are only identical when we're at the first template controller (since the controller
        // is assigned to the proxy), so this evaluates to true at most once per node
        if (manifestProxy === manifest) {
          currentController.template = manifest;
          manifestProxy = currentController;
        } else {
          currentController.templateController = previousController;
          currentController.template = previousController.template;
          previousController.template = currentController;
        }
        previousController = currentController;
      } else {
        // a regular custom attribute
        this.bindCustomAttribute(attrSyntax, attrInfo);
      }
    }

    processTemplateControllers(this.dom, manifestProxy, manifest);

    if (replacePart === null) {
      // the proxy is either the manifest itself or the outer-most controller; add it directly to the parent
      parentManifest.childNodes.push(manifestProxy);
    } else {
      // there is a replace-part attribute on this node, so add it to the parts collection of the manifestRoot
      // instead of to the childNodes
      replacePart.parent = parentManifest;
      replacePart.template = manifestProxy;

      // if the current manifest is also the manifestRoot, it means the replace-part sits on a custom
      // element, so add the part to the parent wrapping custom element instead
      const partOwner = manifest === manifestRoot ? parentManifestRoot : manifestRoot;
      partOwner.parts.push(replacePart);

      processReplacePart(this.dom, replacePart, manifestProxy);
    }

    if (Tracer.enabled) { Tracer.leave(); }
  }
开发者ID:aurelia,项目名称:aurelia,代码行数:71,代码来源:template-binder.ts


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