本文整理汇总了TypeScript中ramda.propOr函数的典型用法代码示例。如果您正苦于以下问题:TypeScript propOr函数的具体用法?TypeScript propOr怎么用?TypeScript propOr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了propOr函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
const getBasePathFilter = (pathParts: string[]): ((data: object | object[]) => object) => {
return R.compose(
R.head,
R.filter(
R.compose(
R.equals(`/${R.propOr('', 0, pathParts)}`),
getRoute
)
),
wrap
);
};
示例2: splitBySelector
const extractExamples = (senseOrExampleGroupMarkup: string) => {
const examples = R.pipe(
splitBySelector({ selector: '.EXAMPLE', onlyChildren: true }),
R.map(
R.pipe(
domify,
R.propOr('', 'textContent'),
cleanse
)
)
)(senseOrExampleGroupMarkup)
return examples
}
示例3:
const transformedAssociations = R.map(association => {
const primaryKey = _.first(AppContext.adapters.models.getPrimaryKeys(association.name));
let value;
if (_.isArrayLike(association.value)) {
value = association.value
? R.map(entity => R.propOr(entity, primaryKey, entity))(association.value)
: undefined;
} else {
value = association.value
? R.propOr(association.value, primaryKey, association.value)
: undefined;
}
logger.debug(TAG, 'handle association', { association, value, primaryKey });
return { ...association, value };
})(pairedWrappedAssociations);
示例4: async
export const send = async (ctx: Koa.Context, error: iError, data: Function): Promise<void> => {
try {
const response: ApiResponse = await data(ctx);
const status = R.propOr(200, 'status', response);
ctx.status = status;
ctx.body = maybeProp('parts', response).fold(
() => R.propOr('', 'data', response),
({ meta = {}, body = {} }) => ({
meta: {
...meta,
status,
message: responseStatuses.success
},
body
})
);
} catch (e) {
sendError(ctx, e, error);
}
};
示例5: select
const menuSagaFunctions = {
*init() {
try {
const { roles, user } = yield select((state: RootState) => state.security);
if (user) {
if (roles && roles.items) {
const currentRoles = R.compose(
R.filter(role => {
// 判断返回的是否是 ids
if (user.roles && _.isObjectLike(user.roles[0])) {
return R.contains(role.id)(R.values(R.pluck('id', user.roles)));
}
return R.contains(role.id)(user.roles);
}),
R.propOr([], 'items'),
)(roles);
logger.debug('[init]', 'current roles is', currentRoles);
const isSysAdmin = !!R.find(role => role.name === 'SYS_ADMIN')(currentRoles);
logger.debug('[init]', 'current user isSysAdmin', isSysAdmin);
const authoritiesList = R.compose(
// remove null values
R.filter(R.identity),
// 后端返回字符串时需要反序列化为 JSON
R.map(role => {
const each = R.prop('authorities')(role);
return R.is(String, each) ? JSON.parse(each) : each;
}),
)(currentRoles);
示例6: keys
// keys :: {k: v} → [k]
keys(obj) {
return R.keys(obj)
},
// values :: {k: v} → [v]
values(obj) {
return R.values(obj)
},
// prop :: s → {s: a} → a | Undefined
prop(obj) {
return R.prop(obj)
},
// propOr :: a → String → Object → a
propOr(defaultVal, fieldsArr, obj) {
return R.propOr(defaultVal, fieldsArr, obj)
},
// [Idx] → {a} → a | Undefined
// Idx = String | Int
path(fieldsLevelArr, obj) {
return R.path(fieldsLevelArr, obj)
},
pathOr(defaultVal, fieldsLevelArr, obj) {
return R.path(defaultVal, fieldsLevelArr, obj)
},
// pick :: [k] → {k: v} → {k: v}
pick(fieldsArr, obj) {
return R.pick(fieldsArr, obj)
},
// assoc/assocPath
示例7: propOr
export const getDisplayNameForGroup = (key: string) =>
propOr('Other', key, groupNameMap);
示例8: BundleAnalyzerPlugin
output: {
wrap_iife: true
}
}
})
]
},
plugins: [
new BundleAnalyzerPlugin({
analyzerMode: 'static',
reportFilename: path.join('..', 'report.html')
}),
new MiniCssExtractPlugin({
filename: path.join('css', '[name].css')
}),
new ZipPlugin({
filename: `${pkg.version}.zip`
})
]
}
const getMergedConfigByEnv = R.converge(R.mergeDeepWith(R.concat), [
R.prop('default'),
R.propOr({}, nodeEnv)
])
export default getMergedConfigByEnv({
default: defaultConfig,
development: developmentConfig,
production: productionConfig
})