當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Result.error方法代碼示例

本文整理匯總了TypeScript中@ephox/katamari.Result.error方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Result.error方法的具體用法?TypeScript Result.error怎麽用?TypeScript Result.error使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在@ephox/katamari.Result的用法示例。


在下文中一共展示了Result.error方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1:

 const cGetDialogLabelId = Chain.binder((dialogE: Element) => {
   if (Attr.has(dialogE, 'aria-labelledby')) {
     const labelId = Attr.get(dialogE, 'aria-labelledby');
     return labelId.length > 0 ? Result.value(labelId) : Result.error('Dialog has zero length aria-labelledby attribute');
   } else {
     return Result.error('Dialog has no aria-labelledby attribute');
   }
 });
開發者ID:tinymce,項目名稱:tinymce,代碼行數:8,代碼來源:SilverDialogAriaLabelTest.ts

示例2: load

 return Future.nu(function (resolve) {
   load(
     url,
     Fun.compose(resolve, Fun.constant(Result.value(url))),
     Fun.compose(resolve, Fun.constant(Result.error(url)))
   );
 });
開發者ID:tinymce,項目名稱:tinymce,代碼行數:7,代碼來源:StyleSheetLoader.ts

示例3:

const extractGlobal = (url: string): Result<Record<string, any>, any> => {
  if (Global.tinymce[GLOBAL_NAME]) {
    const result = Result.value(Global.tinymce[GLOBAL_NAME]);
    delete Global.tinymce[GLOBAL_NAME];
    return result;
  } else {
    return Result.error(`URL ${url} did not contain the expected format for emoticons`);
  }
};
開發者ID:tinymce,項目名稱:tinymce,代碼行數:9,代碼來源:EmojiDatabase.ts

示例4:

 return Chain.binder(function (_) {
   const tableElm = Element.fromHtml(html);
   const startElm = Hierarchy.follow(tableElm, startPath).getOrDie();
   const endElm = Hierarchy.follow(tableElm, endPath).getOrDie();
   return SimpleTableModel.subsection(SimpleTableModel.fromDom(tableElm), startElm, endElm).fold(
     Fun.constant(Result.error('Failed to get the subsection')),
     Result.value
   );
 });
開發者ID:aha-app,項目名稱:tinymce-word-paste-filter,代碼行數:9,代碼來源:SimpleTableModelTest.ts

示例5:

 Chain.binder((rect: ClientRect) => {
   const middle = { x: rect.left + rect.width / 2, y: rect.top + rect.height / 2 };
   const range = document.caretRangeFromPoint(middle.x, middle.y);
   if (! range) {
     return Result.error('Could not find a range at coordinate: (' + middle.x + ', ' + middle.y + ')');
   } else {
     return SelectorExists.closest(Element.fromDom(range.startContainer), selector) ? Result.value(rect) : Result.error('Range was not within: "' + selector + '". Are you sure that it is on top of the dialog?');
   }
 })
開發者ID:tinymce,項目名稱:tinymce,代碼行數:9,代碼來源:SilverDialogPopupsTest.ts

示例6: function

export const parseSize = function (sizeText: string): Result<Size, string> {
  const numPattern = /^\s*(\d+(?:\.\d+)?)\s*(|cm|mm|in|px|pt|pc|em|ex|ch|rem|vw|vh|vmin|vmax|%)\s*$/;
  const match = numPattern.exec(sizeText);
  if (match !== null) {
    const value = parseFloat(match[1]);
    const unit = match[2] as SizeUnit;
    return Result.value({ value, unit });
  } else {
    return Result.error(sizeText);
  }
};
開發者ID:tinymce,項目名稱:tinymce,代碼行數:11,代碼來源:SizeInputModel.ts

示例7: parseSize

UnitTest.test('SizeInputParsingTest', () => {
  const check = (expected: Result<Size, string>, text: string) => {
    const result = parseSize(text);
    expected.fold((err) => {
      result.fold((resultErr) => {
        assert.eq(err, resultErr);
      }, (resultValue) => {
        assert.fail('parseSize should have failed but succeeded with value:\n' + JSON.stringify(resultValue));
      });
    }, (value: Size) => {
      result.fold((resultErr) => {
        assert.fail('parseSize should have succeeded but failed with err: "' + resultErr + '"');
      }, (resultValue) => {
        assert.eq(value, resultValue);
      });
    });
  };

  check(Result.error(''), '');
  check(Result.error('px'), 'px');
  check(Result.error('a'), 'a');
  check(Result.error('blah'), 'blah');
  check(Result.error('1a'), '1a');
  // check negative numbers are not allowed
  check(Result.error('-1px'), '-1px');
  // check the empty unit
  check(Result.value(nuSize(1, '')), '1');
  // check various forms of padding
  check(Result.value(nuSize(1, 'px')), '1px');
  check(Result.value(nuSize(1, 'px')), '    1px');
  check(Result.value(nuSize(1, 'px')), '1px     ');
  check(Result.value(nuSize(1, 'px')), '    1px     ');
  check(Result.value(nuSize(1, 'px')), '    1    px     ');
  check(Result.value(nuSize(1.25, 'px')), '    1.25    px     ');
  // check that all units work
  Arr.each(units, (unit) => {
    check(Result.error(unit), unit);
    check(Result.value(nuSize(4, unit as SizeUnit)), '4' + unit);
  });

  const arbPad = Jsc.array(Jsc.elements(' \t'.split(''))).smap(
    function (arr) { return arr.join(''); },
    function (s) { return s.split(''); }
  );

  Jsc.property(
    'Valid size strings should be parseable',
    arbPad, Jsc.number(0, largeSensible), arbPad, Jsc.oneof(Jsc.elements(units)), arbPad,
    function (pad1: string, nonNegNumber: number, pad2: string, unit: SizeUnit, pad3: string) {
      const str = pad1 + nonNegNumber + pad2 + unit + pad3;
      const parsed = parseSize(str);
      const size = parsed.toOption().getOrNull();
      return Jsc.eq(nuSize(nonNegNumber, unit), size);
    }
  );
});
開發者ID:tinymce,項目名稱:tinymce,代碼行數:56,代碼來源:SizeInputParsingTest.ts

示例8: getRoot

 const validatingBehaviours = spec.validation.map((vl) => {
   return Invalidating.config({
     getRoot(input) {
       return Traverse.parent(input.element());
     },
     invalidClass: 'tox-invalid',
     validator: {
       validate(input) {
         const v = Representing.getValue(input);
         const result = vl.validator(v);
         return Future.pure(result === true ? Result.value(v) : Result.error(result));
       },
       validateOnLoad: vl.validateOnLoad
     }
   });
 }).toArray();
開發者ID:tinymce,項目名稱:tinymce,代碼行數:16,代碼來源:TextField.ts

示例9:

 const cFindNthIn = (selector, n) => Chain.binder((elem: Element) => {
   const matches = UiFinder.findAllIn(elem, selector);
   return matches.length > 0 && n < matches.length ? Result.value(matches[n]) :
     Result.error(`Could not find match ${n} of selector: ${selector}`);
 });
開發者ID:tinymce,項目名稱:tinymce,代碼行數:5,代碼來源:OxideCollectionComponentTest.ts

示例10: return

 const result = data.bind((dimensions) => {
   return ((Type.isString(dimensions.width) || Type.isNumber(dimensions.width)) && (Type.isString(dimensions.height) || Type.isNumber(dimensions.height))) ?
     Result.value({ width: String(dimensions.width), height: String(dimensions.height) }) :
     Result.error(undefined);
 });
開發者ID:tinymce,項目名稱:tinymce,代碼行數:5,代碼來源:Dialog.ts


注:本文中的@ephox/katamari.Result.error方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。