本文整理汇总了TypeScript中@ephox/katamari.Option.fold方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Option.fold方法的具体用法?TypeScript Option.fold怎么用?TypeScript Option.fold使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@ephox/katamari.Option
的用法示例。
在下文中一共展示了Option.fold方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
const setSelection = function (editor: Editor, forward: boolean, pos: Option<CaretPosition>) {
pos.fold(
function () {
editor.focus();
},
function (pos) {
editor.selection.setRng(pos.toRange(), forward);
}
);
};
示例2: converter
const check = (converter: SizeConversion) => (expected: Option<Size>, input: Size) => {
const result = converter(input);
expected.fold(() => {
assert.eq(true, result.isNone(), 'Expected none');
}, (size) => {
result.fold(() => {
assert.fail('Expected size');
}, (resultSize) => {
assert.eq(size, resultSize);
});
});
};
示例3: linkImageFigure
const createLink = (editor: Editor, selectedElm: Element, text: Option<string>, linkAttrs: Record<string, string>) => {
if (isImageFigure(selectedElm)) {
linkImageFigure(editor, selectedElm, linkAttrs);
} else {
text.fold(
() => {
editor.execCommand('mceInsertLink', false, linkAttrs);
},
(text) => {
editor.insertContent(editor.dom.createHTML('a', linkAttrs, editor.dom.encode(text)));
}
);
}
};
示例4: return
const makeIcon = (name, errId: Option<string>, icon = name, label = name) => {
return ({
dom: {
tag: 'div',
classes: ['tox-icon', 'tox-control-wrap__status-icon-' + name],
innerHtml: Icons.get(icon, providersBackstage.icons),
attributes: {
'title': providersBackstage.translate(label),
'aria-live': 'polite',
...errId.fold(() => ({ }), (id) => ({ id }))
}
}
});
};
示例5: fail
const cExtractTableFromDeleteAction = Chain.binder(function (actionOpt: Option<any>) {
return actionOpt
.fold(
fail('unexpected nothing'),
function (action) {
return action.fold(
function (table) {
return Result.value(Html.getOuter(table));
},
fail('unexpected action')
);
}
);
});
示例6:
const emojisFrom = (list: EmojiEntry[], pattern: string, maxResults: Option<number>): Array<{value: string, icon: string, text: string }> => {
const matches = [];
const lowerCasePattern = pattern.toLowerCase();
const reachedLimit = maxResults.fold(() => Fun.never, (max) => (size) => size >= max);
for (let i = 0; i < list.length; i++) {
// TODO: more intelligent search by showing title matches at the top, keyword matches after that (use two arrays and concat at the end)
if (pattern.length === 0 || emojiMatches(list[i], lowerCasePattern)) {
matches.push({
value: list[i].char,
text: list[i].title,
icon: list[i].char
});
if (reachedLimit(matches.length)) {
break;
}
}
}
return matches;
};
示例7: getAttr
const identify = (editor: Editor, annotationName: Option<string>): Option<{uid: string, name: string, elements: any[]}> => {
const rng = editor.selection.getRng();
const start = Element.fromDom(rng.startContainer);
const root = Element.fromDom(editor.getBody());
const selector = annotationName.fold(
() => '.' + Markings.annotation(),
(an) => `[${Markings.dataAnnotation()}="${an}"]`
);
const newStart = Traverse.child(start, rng.startOffset).getOr(start);
const closest = SelectorFind.closest(newStart, selector, (n) => {
return Compare.eq(n, root);
});
const getAttr = (c, property: string): Option<any> => {
if (Attr.has(c, property)) {
return Option.some(Attr.get(c, property));
} else {
return Option.none();
}
};
return closest.bind((c) => {
return getAttr(c, `${Markings.dataAnnotationId()}`).bind((uid) =>
getAttr(c, `${Markings.dataAnnotation()}`).map((name) => {
const elements = findMarkers(editor, uid);
return {
uid,
name,
elements
};
})
);
});
};