本文整理汇总了TypeScript中lodash/fp.uniq函数的典型用法代码示例。如果您正苦于以下问题:TypeScript uniq函数的具体用法?TypeScript uniq怎么用?TypeScript uniq使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了uniq函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getTimelineData
public async getTimelineData(
request: FrameworkRequest,
options: EventsRequestOptions
): Promise<TimelineData> {
const queryOptions = cloneDeep(options);
queryOptions.fields = uniq([
...queryOptions.fieldRequested,
...reduceFields(queryOptions.fields, eventFieldsMap),
]);
delete queryOptions.fieldRequested;
const response = await this.framework.callWithRequest<EventHit, TermAggregation>(
request,
'search',
buildQuery(queryOptions)
);
const { limit } = options.pagination;
const totalCount = getOr(0, 'hits.total.value', response);
const hits = response.hits.hits;
const timelineEdges: TimelineEdges[] = hits.map(hit =>
formatTimelineData(options.fieldRequested, options.fields, hit, eventFieldsMap)
);
const hasNextPage = timelineEdges.length === limit + 1;
const edges = hasNextPage ? timelineEdges.splice(0, limit) : timelineEdges;
const lastCursor = get('cursor', last(edges));
return { edges, totalCount, pageInfo: { hasNextPage, endCursor: lastCursor } };
}
示例2: uniq
export const formatTimelineData = (
dataFields: ReadonlyArray<string>,
ecsFields: ReadonlyArray<string>,
hit: EventHit,
fieldMap: Readonly<Record<string, string>>
) =>
uniq([...ecsFields, ...dataFields]).reduce<TimelineEdges>(
(flattenedFields, fieldName) => {
flattenedFields.node._id = hit._id;
flattenedFields.node._index = hit._index;
flattenedFields.node.ecs._id = hit._id;
flattenedFields.node.ecs._index = hit._index;
if (hit.sort && hit.sort.length > 1) {
flattenedFields.cursor.value = hit.sort[0];
flattenedFields.cursor.tiebreaker = hit.sort[1];
}
return mergeTimelineFieldsWithHit(
fieldName,
flattenedFields,
fieldMap,
hit,
dataFields,
ecsFields
);
},
{
node: { ecs: { _id: '' }, data: [], _id: '', _index: '' },
cursor: {
value: '',
tiebreaker: null,
},
}
);
示例3: getOr
export const addTimelineNoteToEvent = ({
id,
noteId,
eventId,
timelineById,
}: AddTimelineNoteToEventParams): TimelineById => {
const timeline = timelineById[id];
const existingNoteIds = getOr([], `eventIdToNoteIds.${eventId}`, timeline);
return {
...timelineById,
[id]: {
...timeline,
eventIdToNoteIds: {
...timeline.eventIdToNoteIds,
...{ [eventId]: uniq([...existingNoteIds, noteId]) },
},
},
};
};