当前位置: 首页>>代码示例>>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;未经允许,请勿转载。