本文整理匯總了TypeScript中@ephox/sugar.Traverse.firstChild方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Traverse.firstChild方法的具體用法?TypeScript Traverse.firstChild怎麽用?TypeScript Traverse.firstChild使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類@ephox/sugar.Traverse
的用法示例。
在下文中一共展示了Traverse.firstChild方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: createEntry
const parseItem: Parser = (depth: number, itemSelection: Option<ItemSelection>, selectionState: Cell<boolean>, item: Element): Entry[] => {
return Traverse.firstChild(item).filter(isList).fold(() => {
// Update selectionState (start)
itemSelection.each((selection) => {
if (Compare.eq(selection.start, item)) {
selectionState.set(true);
}
});
const currentItemEntry = createEntry(item, depth, selectionState.get());
// Update selectionState (end)
itemSelection.each((selection) => {
if (Compare.eq(selection.end, item)) {
selectionState.set(false);
}
});
const childListEntries: Entry[] = Traverse.lastChild(item)
.filter(isList)
.map((list) => parseList(depth, itemSelection, selectionState, list))
.getOr([]);
return currentItemEntry.toArray().concat(childListEntries);
}, (list) => parseList(depth, itemSelection, selectionState, list));
};
示例2: function
const getFirstChildren = function (node) {
return Traverse.firstChild(node).fold(
Fun.constant([node]),
function (child) {
return [node].concat(getFirstChildren(child));
}
);
};
示例3: updateSelectionState
const parseItem: Parser = (depth: number, itemSelection: Option<ItemTuple>, selectionState: Cell<boolean>, item: Element): Entry[] => {
const curriedParseList = Fun.curry(parseList, depth, itemSelection, selectionState);
const updateSelectionState = (itemRange: ItemRange) => itemSelection.each((selection) => {
if (Compare.eq(itemRange === ItemRange.Start ? selection.start : selection.end, item)) {
selectionState.set(itemRange === ItemRange.Start);
}
});
return Traverse.firstChild(item).filter(isList).fold(() => {
updateSelectionState(ItemRange.Start);
const fromCurrentItem: Entry = createEntry(item, depth, selectionState.get());
updateSelectionState(ItemRange.End);
const fromChildList: Entry[] = Traverse.lastChild(item).filter(isList).map(curriedParseList).getOr([]);
return [ fromCurrentItem, ...fromChildList ];
}, curriedParseList);
};
示例4:
const hasFirstChildList = (li: Element) => {
return Traverse.firstChild(li).map(isList).getOr(false);
};