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


TypeScript ramda.ifElse函數代碼示例

本文整理匯總了TypeScript中ramda.ifElse函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript ifElse函數的具體用法?TypeScript ifElse怎麽用?TypeScript ifElse使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


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

示例1: compose

getIdOrNullFor = type => compose(
  ifElse(isNil, always(null), compose(
    ifElse(
      contains(type),
      compose<string, string[], string, number, Record<string, number>>(
        objOf(`${type}_id`), Number, last, split('-'),
      ),
      always(null),
    ),
  )),
);
開發者ID:displague,項目名稱:manager,代碼行數:11,代碼來源:createDevicesFromStrings.ts

示例2: adapter

export function adapter (runSA: StreamAdapter) {
  let adapt: (streamOrFunc: Observable<any> | StreamFunction) => any = ifElse(
    isObservable,
    adaptStream,
    ifElse(
      is(Function),
      adaptFunction,
      identity))

  function adaptStream (stream: Observable<any>) {
    return convertStream(stream, RxAdapter, runSA)
  }

  function adaptFunction (func: StreamFunction) {
    return (...args: any[]) => adaptStream(func(...args))
  }

  return adapt
}
開發者ID:goodmind,項目名稱:cycle-telegram,代碼行數:19,代碼來源:index.ts

示例3: curryN

let transformReq = curryN(2, (req: Request, multipart: boolean) => ifElse(
  () => multipart,
  pipe<any, any, any, any>(
    mapObjIndexed((v: any, k: string) => v
      ? req[propOr(false, 'path', v) ? 'attach' : 'field'](k, v)
      : req),
    values,
    last
  ),
  req.send.bind(req)
))
開發者ID:goodmind,項目名稱:cycle-telegram,代碼行數:11,代碼來源:api-request.ts

示例4: compose

import { NoContent } from './no-content';

import { DataResolver } from './app.resolver';

import { routes as blogRoutes, asyncRoutes as blogAsyncRoutes } from './blog/blog.routing';

import { prop, compose, split, find, trim, equals, nth, ifElse, identity } from 'ramda';

export const appNavLinks: NavigationConfig = [
  ...Pages.navLinks,
  ...Layouts.navLinks,
  ...Authentication.navLinks,
];

const layout = compose(
    ifElse(identity, compose(nth(1), split('=')), identity),
    find(compose(equals('layout'), trim, nth(0), split('='))),
    split(';')
  )(document.cookie);

const layouts = {
  'horizontal': HorizontalLayout,
  'vertical' : VerticalLayout
};

export const routes: RouterConfig = [
  {
    path: '',
    component: layouts[layout],
    children: [
      ...Pages.routes,
開發者ID:the-fool,項目名稱:attacus-atlas,代碼行數:31,代碼來源:app.routes.ts

示例5: isWithin

export const NONE = null
export const CLIENT_ERROR = 'CLIENT_ERROR'
export const SERVER_ERROR = 'SERVER_ERROR'
export const TIMEOUT_ERROR = 'TIMEOUT_ERROR'
export const CONNECTION_ERROR = 'CONNECTION_ERROR'
export const NETWORK_ERROR = 'NETWORK_ERROR'
export const UNKNOWN_ERROR = 'UNKNOWN_ERROR'
export const CANCEL_ERROR = 'CANCEL_ERROR'

const TIMEOUT_ERROR_CODES = ['ECONNABORTED']
const NODEJS_CONNECTION_ERROR_CODES = ['ENOTFOUND', 'ECONNREFUSED', 'ECONNRESET']
const in200s = isWithin(200, 299)
const in400s = isWithin(400, 499)
const in500s = isWithin(500, 599)
const statusNil = ifElse(isNil, always(undefined), prop('status'))

/**
 * What's the problem for this axios response?
 */
export const getProblemFromError = error => {
  // first check if the error message is Network Error (set by axios at 0.12) on platforms other than NodeJS.
  if (error.message === 'Network Error') return NETWORK_ERROR
  if (axios.isCancel(error)) return CANCEL_ERROR

  // then check the specific error code
  return cond([
    // if we don't have an error code, we have a response status
    [isNil, () => getProblemFromStatus(statusNil(error.response))],
    [containsText(TIMEOUT_ERROR_CODES), always(TIMEOUT_ERROR)],
    [containsText(NODEJS_CONNECTION_ERROR_CODES), always(CONNECTION_ERROR)],
開發者ID:skellock,項目名稱:apisauce,代碼行數:30,代碼來源:apisauce.ts


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