當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。