当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Option.fold方法代码示例

本文整理汇总了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);
    }
  );
};
开发者ID:tinymce,项目名称:tinymce,代码行数:10,代码来源:DeleteElement.ts

示例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);
     });
   });
 };
开发者ID:tinymce,项目名称:tinymce,代码行数:12,代码来源:SizeInputConverterTest.ts

示例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)));
      }
    );
  }
};
开发者ID:tinymce,项目名称:tinymce,代码行数:14,代码来源:Utils.ts

示例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 }))
       }
     }
   });
 };
开发者ID:tinymce,项目名称:tinymce,代码行数:14,代码来源:UrlInput.ts

示例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')
         );
       }
     );
 });
开发者ID:danielpunkass,项目名称:tinymce,代码行数:14,代码来源:TableDeleteActionTest.ts

示例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;
};
开发者ID:tinymce,项目名称:tinymce,代码行数:19,代码来源:Lookup.ts

示例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
        };
      })
    );
  });
};
开发者ID:danielpunkass,项目名称:tinymce,代码行数:37,代码来源:Identification.ts


注:本文中的@ephox/katamari.Option.fold方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。