本文整理汇总了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),
),
)),
);
示例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
}
示例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)
))
示例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,
示例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)],