本文整理匯總了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
};
})
);
});
};