本文整理汇总了TypeScript中ramda.when函数的典型用法代码示例。如果您正苦于以下问题:TypeScript when函数的具体用法?TypeScript when怎么用?TypeScript when使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了when函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: sendSubscriptions
/**
* Sends all subscribed values to the Reactotron app.
*
* @param node The tree to grab the state data from
*/
function sendSubscriptions(state: any) {
// this is unreadable
const changes = pipe(
map(when(isNil, always(""))) as any,
filter(endsWith(".*")),
map((key: string) => {
const keyMinusWildcard = slice(0, -2, key)
const value = dotPath(keyMinusWildcard, state)
if (is(Object, value) && !isNilOrEmpty(value)) {
return pipe(keys, map(key => `${keyMinusWildcard}.${key}`))(value)
}
return []
}) as any,
concat(map(when(isNil, always("")), subscriptions)),
flatten,
reject(endsWith(".*")) as any,
uniq as any,
sortBy(identity) as any,
map((key: string) => ({
path: key,
value: isNilOrEmpty(key) ? state : dotPath(key, state),
})),
)(subscriptions)
reactotron.stateValuesChange(changes)
}
示例2: curry
export default curry((defaultValue: number, v?: null | string | number) =>
compose<
string | number | null | undefined,
number | null | undefined,
number>(
defaultTo(defaultValue),
when(compose(not, isEmpty), (value: string) => +value),
)(v));
示例3: compose
fs.readdirSync(root).map((name: string) =>
compose(
getOrElse(null),
when(isDirectory, filePath =>
getPrefixedRoutesFromMap(getPrefixedRoute)(
requireFilePath(filePath, 'index.js'),
requireFilePath(filePath, 'config.json')
)
)
)(resolve(root, name))
示例4: async
return async (ctx, next) => {
R.when(isTruthy, () => {
const roles = R.pathOr([], ['state', 'accessRoles'], ctx) as string[];
const hasAccess = roles.some(accessMap(ctx));
if (roles.length && !hasAccess) ctx.throw(401, 'Unauthorised access to endpoint');
})(accessMap);
await next();
};
示例5: when
export const setHeaders = (headers: any = {}) =>
when(() => isNotEmpty(headers), set(L.headers, headers));
示例6:
const apply = (m, s) => R.when(isModuloOf(m), R.always(s))