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