本文整理汇总了TypeScript中@aurelia/runtime.IDOM.createElement方法的典型用法代码示例。如果您正苦于以下问题:TypeScript IDOM.createElement方法的具体用法?TypeScript IDOM.createElement怎么用?TypeScript IDOM.createElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@aurelia/runtime.IDOM
的用法示例。
在下文中一共展示了IDOM.createElement方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例2: 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);
}