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


TypeScript Result.value方法代碼示例

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


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

示例1: 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

示例2:

 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

示例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: 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

示例5: 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

示例6: err

 const formatOrCmd = <T> (name: string, onFormat: (formats: string[]) => T, onCommand: (cmd: string, value: any) => T): Result<T, PatternError> => {
   if (pattern.format !== undefined) {
     let formats: string[];
     if (Type.isArray(pattern.format)) {
       if (!Arr.forall(pattern.format, Type.isString)) {
         return err(name + ' pattern has non-string items in the `format` array');
       }
       formats = pattern.format;
     } else if (Type.isString(pattern.format)) {
       formats = [pattern.format];
     } else {
       return err(name + ' pattern has non-string `format` parameter');
     }
     return Result.value(onFormat(formats));
   } else if (pattern.cmd !== undefined) {
     if (!Type.isString(pattern.cmd)) {
       return err(name + ' pattern has non-string `cmd` parameter');
     }
     return Result.value(onCommand(pattern.cmd, pattern.value));
   } else {
     return err(name + ' pattern is missing both `format` and `cmd` parameters');
   }
 };
開發者ID:tinymce,項目名稱:tinymce,代碼行數:23,代碼來源:Pattern.ts

示例7: 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

示例8:

          validate: (input) => {
            const inputValue = Representing.getValue(input);
            // Consider empty strings valid colours
            if (inputValue.length === 0) {
              return Future.pure(Result.value(true));
            } else {
              const span = Element.fromTag('span');
              Css.set(span, 'background-color', inputValue);

              const res = Css.getRaw(span, 'background-color').fold(
                // TODO: Work out what we want to do here.
                () => Result.error('blah'),
                (_) => Result.value(inputValue)
              );

              return Future.pure(res);
            }
          }
開發者ID:tinymce,項目名稱:tinymce,代碼行數:18,代碼來源:ColorInput.ts

示例9:

 lazySink: () => Result.value(spec.sink)
開發者ID:tinymce,項目名稱:tinymce,代碼行數:1,代碼來源:ContextUi.ts

示例10:

 Chain.binder((ts) => ts.length === 1 ? Result.value(ts[0]) : Result.error('Did not find exactly 1 of ' +
   selector + '. Found: ' + ts.length))
開發者ID:tinymce,項目名稱:tinymce,代碼行數:2,代碼來源:UiChainUtils.ts


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