本文整理匯總了TypeScript中dom5/lib/index-next.predicates.OR方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript predicates.OR方法的具體用法?TypeScript predicates.OR怎麽用?TypeScript predicates.OR使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類dom5/lib/index-next.predicates
的用法示例。
在下文中一共展示了predicates.OR方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: simpleSelectorToPredicate
function simpleSelectorToPredicate(
selector: cssWhat.Simple, isPolymerTemplate: boolean) {
switch (selector.type) {
case 'adjacent':
case 'child':
case 'descendant':
case 'parent':
case 'sibling':
case 'pseudo':
throw new Error(`Unsupported CSS operator: ${selector.type}`);
case 'attribute':
if (isPolymerTemplate) {
return dom5.predicates.OR(
attributeSelectorToPredicate(selector),
attributeSelectorToPredicate(
{...selector, name: selector.name + '$'}));
}
return attributeSelectorToPredicate(selector);
case 'tag':
return dom5.predicates.hasTagName(selector.name);
case 'universal':
return () => true;
}
const never: never = selector;
throw new Error(`Unexpected node type from css parser: ${never}`);
}
示例2: elementSelectorToPredicate
export function elementSelectorToPredicate(
simpleSelector: string,
isPolymerTemplate: boolean = false): dom5.Predicate {
const parsed = cssWhat(simpleSelector);
// The output of cssWhat is two levels of arrays. The outer level are any
// selectors joined with a comma, so it matches if any of the inner selectors
// match. The inner array are simple selectors like `.foo` and `#bar` which
// must all match.
return dom5.predicates.OR(...parsed.map((simpleSelectors) => {
return dom5.predicates.AND(...simpleSelectors.map(
(selector) => simpleSelectorToPredicate(selector, isPolymerTemplate)));
}));
}