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


TypeScript runtime.IDOM類代碼示例

本文整理匯總了TypeScript中@aurelia/runtime.IDOM的典型用法代碼示例。如果您正苦於以下問題:TypeScript IDOM類的具體用法?TypeScript IDOM怎麽用?TypeScript IDOM使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了IDOM類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: RenderPlan

function createElementForTag<T extends INode>(dom: IDOM<T>, tagName: string, props?: Record<string, string | HTMLTargetedInstruction>, children?: ArrayLike<unknown>): RenderPlan<T> {
  if (Tracer.enabled) { Tracer.enter('createElement', 'createElementForTag', slice.call(arguments)); }
  const instructions: HTMLTargetedInstruction[] = [];
  const allInstructions: HTMLTargetedInstruction[][] = [];
  const dependencies: IRegistry[] = [];
  const element = dom.createElement(tagName);
  let hasInstructions = false;

  if (props) {
    Object.keys(props)
      .forEach(to => {
        const value = props[to];

        if (isHTMLTargetedInstruction(value)) {
          hasInstructions = true;
          instructions.push(value);
        } else {
          dom.setAttribute(element, to, value);
        }
      });
  }

  if (hasInstructions) {
    dom.makeTarget(element);
    allInstructions.push(instructions);
  }

  if (children) {
    addChildren(dom, element, children, allInstructions, dependencies);
  }

  if (Tracer.enabled) { Tracer.leave(); }
  return new RenderPlan(dom, element, allInstructions, dependencies);
}
開發者ID:aurelia,項目名稱:aurelia,代碼行數:34,代碼來源:create-element.ts

示例2: processTemplateControllers

/**
 * A (temporary) standalone function that purely does the DOM processing (lifting) related to template controllers.
 * It's a first refactoring step towards separating DOM parsing/binding from mutations.
 */
function processTemplateControllers(dom: IDOM, manifestProxy: IParentNodeSymbol, manifest: IElementSymbol): void {
  const manifestNode = manifest.physicalNode as HTMLElement;
  let current = manifestProxy as TemplateControllerSymbol;
  let currentTemplate: HTMLTemplateElement;
  while ((current as IParentNodeSymbol) !== manifest) {
    if (current.template === manifest) {
      // the DOM linkage is still in its original state here so we can safely assume the parentNode is non-null
      manifestNode.parentNode.replaceChild(current.marker as Node, manifestNode);

      // if the manifest is a template element (e.g. <template repeat.for="...">) then we can skip one lift operation
      // and simply use the template directly, saving a bit of work
      if (manifestNode.nodeName === 'TEMPLATE') {
        current.physicalNode = manifestNode as HTMLTemplateElement;
        // the template could safely stay without affecting anything visible, but let's keep the DOM tidy
        manifestNode.remove();
      } else {
        // the manifest is not a template element so we need to wrap it in one
        currentTemplate = current.physicalNode = dom.createTemplate() as HTMLTemplateElement;
        currentTemplate.content.appendChild(manifestNode);
      }
    } else {
      currentTemplate = current.physicalNode = dom.createTemplate() as HTMLTemplateElement;
      currentTemplate.content.appendChild(current.marker as Node);
    }
    manifestNode.removeAttribute(current.syntax.rawName);
    current = current.template as TemplateControllerSymbol;
  }
}
開發者ID:aurelia,項目名稱:aurelia,代碼行數:32,代碼來源:template-binder.ts

示例3: HydrateElementInstruction

function createElementForType<T extends INode>(dom: IDOM<T>, Type: ICustomElementType<T>, props?: object, children?: ArrayLike<unknown>): RenderPlan<T> {
  if (Tracer.enabled) { Tracer.enter('createElement', 'createElementForType', slice.call(arguments)); }
  const tagName = Type.description.name;
  const instructions: HTMLTargetedInstruction[] = [];
  const allInstructions = [instructions];
  const dependencies: IRegistry[] = [];
  const childInstructions: HTMLTargetedInstruction[] = [];
  const bindables = Type.description.bindables;
  const element = dom.createElement(tagName);

  dom.makeTarget(element);

  if (!dependencies.includes(Type)) {
    dependencies.push(Type);
  }

  instructions.push(new HydrateElementInstruction(tagName, childInstructions));

  if (props) {
    Object.keys(props)
      .forEach(to => {
        const value: HTMLTargetedInstruction | string = props[to];

        if (isHTMLTargetedInstruction(value)) {
          childInstructions.push(value);
        } else {
          const bindable = bindables[to];

          if (bindable) {
            childInstructions.push({
              type: TargetedInstructionType.setProperty,
              to,
              value
            });
          } else {
            childInstructions.push(new SetAttributeInstruction(value, to));
          }
        }
      });
  }

  if (children) {
    addChildren(dom, element, children, allInstructions, dependencies);
  }

  if (Tracer.enabled) { Tracer.leave(); }
  return new RenderPlan<T>(dom, element, allInstructions, dependencies);
}
開發者ID:aurelia,項目名稱:aurelia,代碼行數:48,代碼來源:create-element.ts

示例4: switch

function addChildren<T extends INode>(dom: IDOM<T>, parent: T, children: ArrayLike<unknown>, allInstructions: HTMLTargetedInstruction[][], dependencies: IRegistry[]): void {
  for (let i = 0, ii = children.length; i < ii; ++i) {
    const current = children[i];

    switch (typeof current) {
      case 'string':
        dom.appendChild(parent, dom.createTextNode(current));
        break;
      case 'object':
        if (dom.isNodeInstance(current)) {
          dom.appendChild(parent, current);
        } else if ('mergeInto' in (current as RenderPlan)) {
          (current as RenderPlan<T>).mergeInto(parent, allInstructions, dependencies);
        }
    }
  }
}
開發者ID:aurelia,項目名稱:aurelia,代碼行數:17,代碼來源:create-element.ts

示例5: constructor

  constructor(dom: IDOM<Node>, $customElement: ICustomElement<Node>, host: Node) {
    if (host.childNodes.length) {
      this.childNodes = PLATFORM.toArray(host.childNodes);
    } else {
      this.childNodes = PLATFORM.emptyArray;
    }

    this.host = dom.convertToRenderLocation(host) as CustomElementHost<Node>;
    this.host.$customElement = $customElement;
  }
開發者ID:aurelia,項目名稱:aurelia,代碼行數:10,代碼來源:projectors.ts

示例6: processReplacePart

function processReplacePart(dom: IDOM, replacePart: ReplacePartSymbol, manifestProxy: IParentNodeSymbol | ISymbolWithMarker): void {
    let proxyNode: HTMLElement;
    let currentTemplate: HTMLTemplateElement;
    if (manifestProxy.flags & SymbolFlags.hasMarker) {
      proxyNode = (manifestProxy as ISymbolWithMarker).marker as HTMLElement;
    } else {
      proxyNode = manifestProxy.physicalNode as HTMLElement;
    }
    if (proxyNode.nodeName === 'TEMPLATE') {
      // if it's a template element, no need to do anything special, just assign it to the replacePart
      replacePart.physicalNode = proxyNode as HTMLTemplateElement;
    } else {
      // otherwise wrap the replace-part in a template
      currentTemplate = replacePart.physicalNode = dom.createTemplate() as HTMLTemplateElement;
      currentTemplate.content.appendChild(proxyNode);
    }
}
開發者ID:aurelia,項目名稱:aurelia,代碼行數:17,代碼來源:template-binder.ts

示例7:

      .forEach(to => {
        const value = props[to];

        if (isHTMLTargetedInstruction(value)) {
          hasInstructions = true;
          instructions.push(value);
        } else {
          dom.setAttribute(element, to, value);
        }
      });
開發者ID:aurelia,項目名稱:aurelia,代碼行數:10,代碼來源:create-element.ts

示例8: subscribeToChildrenChange

 public subscribeToChildrenChange(callback: () => void): void {
   // TODO: add a way to dispose/disconnect
   this.dom.createNodeObserver(this.shadowRoot, callback, childObserverOptions);
 }
開發者ID:aurelia,項目名稱:aurelia,代碼行數:4,代碼來源:projectors.ts

示例9: bind

 public bind(): void {
   this.nodeObserver = this.dom.createNodeObserver(this.obj, this.handleNodeChange.bind(this), childObserverOptions) as MutationObserver;
 }
開發者ID:aurelia,項目名稱:aurelia,代碼行數:3,代碼來源:select-value-observer.ts

示例10: mergeInto

 /** @internal */
 public mergeInto(parent: T, instructions: HTMLTargetedInstruction[][], dependencies: IRegistry[]): void {
   this.dom.appendChild(parent, this.node);
   instructions.push(...this.instructions);
   dependencies.push(...this.dependencies);
 }
開發者ID:aurelia,項目名稱:aurelia,代碼行數:6,代碼來源:create-element.ts


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