本文整理汇总了TypeScript中ramda.uniqBy函数的典型用法代码示例。如果您正苦于以下问题:TypeScript uniqBy函数的具体用法?TypeScript uniqBy怎么用?TypeScript uniqBy使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了uniqBy函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
const extractItemsBy = primaryKey =>
R.compose(
R.uniqBy(R.prop(primaryKey)),
R.flatten,
R.map(R.path(['data', 'items'])),
R.flatten,
);
示例2: list
export function list(address: string, limit = 100): Promise<Array<T_TX>> {
return request({ url: `${configGet('node')}/transactions/address/${address}/limit/${limit}` })
.then(pipe(
prop('0'),
uniqBy(prop('id')) as any,
))
.then(transactions => parseTx(transactions as any, false));
}
示例3: detectBrowsers
/** returns list of detected browsers */
function detectBrowsers(): Bluebird<Browser[]> {
// we can detect same browser under different aliases
// tell them apart by the full version property
const removeDuplicates = uniqBy(prop('version'))
return Bluebird.mapSeries(browsers, checkOneBrowser)
.then(_.compact)
.then(removeDuplicates) as Bluebird<Browser[]>
}
示例4: uniqBy
export const detect = (goalBrowsers?: Browser[]): Bluebird<FoundBrowser[]> => {
// we can detect same browser under different aliases
// tell them apart by the name and the version property
if (!goalBrowsers) {
goalBrowsers = browsers
}
const removeDuplicates = uniqBy((browser: FoundBrowser) =>
props(['name', 'version'], browser)
)
const compactFalse = (browsers: any[]) => compact(browsers) as FoundBrowser[]
return Bluebird.mapSeries(goalBrowsers, checkBrowser)
.then(flatten)
.then(compactFalse)
.then(removeDuplicates)
}
示例5: listUTX
export function listUTX(address?: string): Promise<Array<T_TX>> {
return request<Array<T_API_TX>>({ url: `${configGet('node')}/transactions/unconfirmed` })
.then(uniqBy(prop('id')))
.then(transactions => filterByAddress(transactions, address))
.then(transactions => parseTx(transactions, true));
}
示例6: error
export async function error (ctx: GraphQLServiceContext, next: () => Promise<void>) {
const {
vtex: {
account,
workspace,
route: {
id,
},
},
} = ctx
let graphQLErrors: any[] | null = null
try {
await next()
graphQLErrors = parseErrorResponse(ctx.graphql.graphqlResponse || {})
}
catch (e) {
const formatError = ctx.graphql.formatters!.formatError
if (e.isGraphQLError) {
const response = JSON.parse(e.message)
graphQLErrors = parseError(response)
ctx.body = response
} else {
graphQLErrors = [formatError(e)]
ctx.body = {errors: graphQLErrors}
}
// Add response
ctx.status = e.statusCode || 500
if (e.headers) {
ctx.set(e.headers)
}
}
finally {
if (graphQLErrors) {
const uniqueErrors = uniqBy((e) => {
if (e.originalError && e.originalError.request) {
return e.originalError.request.path
}
return e
}, graphQLErrors)
console.error(`[node-vtex-api graphql errors] total=${graphQLErrors.length} unique=${uniqueErrors.length}`, uniqueErrors)
ctx.graphql.status = 'error'
// Do not generate etag for errors
ctx.remove(META_HEADER)
ctx.remove(ETAG_HEADER)
// In production errors, add two second cache
if (production) {
ctx.set(CACHE_CONTROL_HEADER, `public, max-age=${TWO_SECONDS_S}`)
} else {
ctx.set(CACHE_CONTROL_HEADER, `no-cache, no-store`)
}
// Log each error to splunk individually
forEach((err: any) => {
// Add pathName to each error
if (err.path) {
err.pathName = generatePathName(err.path)
}
const log = {
...err,
routeId: id,
}
// Grab level from originalError, default to "error" level.
let level = err.originalError && err.originalError.level as LogLevel
if (!level || !(level === LogLevel.Error || level === LogLevel.Warn)) {
level = LogLevel.Error
}
ctx.clients.logger.sendLog('-', log, level).catch((reason) => {
console.error('Error logging error 🙄 retrying once...', reason ? reason.response : '')
ctx.clients.logger.sendLog('-', log, level).catch()
})
}, uniqueErrors)
// Expose graphQLErrors with pathNames to timings middleware
ctx.graphql.graphQLErrors = uniqueErrors
// Show message in development environment
if (!production) {
console.log(getSplunkQuery(account, workspace))
}
} else {
ctx.graphql.status = 'success'
}
}
}