本文整理匯總了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))