MCPcopy Create free account
hub / github.com/angular/angular / addItem

Method addItem

adev/shared-docs/services/search-history.service.ts:52–74  ·  view source on GitHub ↗
(item: SearchResultItem | HistoryItem)

Source from the content-addressed store, hash-verified

50 }
51
52 addItem(item: SearchResultItem | HistoryItem): void {
53 // We don't want to reset nor update the creation date of favorites
54 if (this.history().get(item.id)?.isFavorite) {
55 return;
56 }
57
58 this.updateHistory((map) => {
59 map.set(item.id, {
60 id: item.id,
61 labelHtml: cleanUpHtml(item.labelHtml),
62 subLabelHtml: item.subLabelHtml ? cleanUpHtml(item.subLabelHtml) : undefined,
63 url: item.url,
64 isFavorite: false,
65 createdAt: Date.now(),
66 });
67
68 // `items` still hasn't been updated so we should use `>=`.
69 if (this.items().recent.length >= MAX_RECENT_HISTORY_SIZE) {
70 const {id} = this.items().recent.at(-1)!;
71 map.delete(id);
72 }
73 });
74 }
75
76 removeItem(item: SearchResultItem | HistoryItem): void {
77 this.updateHistory((map) => {

Callers 3

loadItemsFunction · 0.45
loadItemsFunction · 0.45

Calls 6

updateHistoryMethod · 0.95
cleanUpHtmlFunction · 0.85
getMethod · 0.65
setMethod · 0.65
atMethod · 0.45
deleteMethod · 0.45

Tested by 2

loadItemsFunction · 0.36
loadItemsFunction · 0.36