本文整理汇总了TypeScript中ramda.lensPath函数的典型用法代码示例。如果您正苦于以下问题:TypeScript lensPath函数的具体用法?TypeScript lensPath怎么用?TypeScript lensPath使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了lensPath函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: update
(state: State) => {
const update = R.set(
R.lensPath(['notes', noteId, 'label']),
text
)
return update(state)
})
示例2:
(acc: Array<BookmarkTree>, bookmarkTree) => {
if (!acc.length) return [bookmarkTree]
const prevBookmarkTree = R.last(acc)
if (!prevBookmarkTree) throw new Error('prevBookmarkTree must exist')
const updatedBookmarkTree = R.set(
R.lensPath(['parent', 'parentId']),
prevBookmarkTree.parent.id,
bookmarkTree
)
return [...acc, updatedBookmarkTree]
},
示例3: simulateBookmark
[getType(bookmarkCreators.setDragIndicator)]: (
state: BookmarkState,
{payload}: ReturnType<typeof bookmarkCreators.setDragIndicator>
) => {
const parentIndex = state.trees.findIndex((tree) => tree.parent.id === payload.parentId)
if (parentIndex === -1) return state
return R.over(
R.lensPath(['trees', parentIndex, 'children']),
R.insert(payload.index, simulateBookmark({type: CST.BOOKMARK_TYPES.DRAG_INDICATOR})),
removeDragIndicator(state)
)
}
示例4: over
import { BrowserOptions, captureException, init } from '@sentry/browser';
import { lensPath, over } from 'ramda';
import { SENTRY_URL } from 'src/constants';
import redactAccessTokenFromUrl from 'src/utilities/redactAccessTokenFromUrl';
const updateRequestUrl = over(
lensPath(['request', 'url']),
redactAccessTokenFromUrl
);
const beforeSend: BrowserOptions['beforeSend'] = (event, hint) => {
return updateRequestUrl(event);
};
if (SENTRY_URL) {
init({
dsn: SENTRY_URL,
release: process.env.VERSION,
environment: process.env.NODE_ENV,
beforeSend
});
}
window.addEventListener('unhandledrejection', (err: PromiseRejectionEvent) => {
captureException(err.reason);
});
export const reportException = (error: string | Error, extra?: any) => {
if (process.env.NODE_ENV === 'production' && SENTRY_URL) {
captureException(error);
} else {
示例5: lensPath
import Axios, { AxiosError, AxiosPromise, AxiosResponse } from 'axios';
import { compose, isEmpty, isNil, lensPath, not, omit, set, when } from 'ramda';
import { ObjectSchema, ValidationError } from 'yup';
const L = {
url: lensPath(['url']),
method: lensPath(['method']),
params: lensPath(['params']),
data: lensPath(['data']),
xFilter: lensPath(['headers', 'X-Filter']),
validationErrors: lensPath(['validationErrors']),
headers: lensPath(['headers'])
};
const isNotEmpty = compose(
not,
(v: any) => isEmpty(v) || isNil(v)
);
/** URL */
export const setURL = (url: string) => set(L.url, url);
/** METHOD */
export const setMethod = (method: 'GET' | 'POST' | 'PUT' | 'DELETE') =>
set(L.method, method);
/** Param */
export const setParams = (params: any = {}) =>
when(() => isNotEmpty(params), set(L.params, params));
export const setHeaders = (headers: any = {}) =>