From 7b7c96719d242310a9be1fb521017d1428ab961a Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Fri, 15 Dec 2017 18:31:51 +0000 Subject: [PATCH] Optimise PIM page a bit more. --- src/Pim.tsx | 4 ++-- src/journal-processors.tsx | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Pim.tsx b/src/Pim.tsx index 20a4946..3f9d735 100644 --- a/src/Pim.tsx +++ b/src/Pim.tsx @@ -51,10 +51,10 @@ const itemsSelector = createSelector( const collectionInfo = syncJournal.collection; if (collectionInfo.type === 'ADDRESS_BOOK') { - addressBookItems = Object.assign(addressBookItems, syncEntriesToItemMap(collectionInfo, syncEntries)); + addressBookItems = syncEntriesToItemMap(collectionInfo, syncEntries, addressBookItems); collectionsAddressBook.push(collectionInfo); } else if (collectionInfo.type === 'CALENDAR') { - calendarItems = Object.assign(calendarItems, syncEntriesToCalendarItemMap(collectionInfo, syncEntries)); + calendarItems = syncEntriesToCalendarItemMap(collectionInfo, syncEntries, calendarItems); collectionsCalendar.push(collectionInfo); } } diff --git a/src/journal-processors.tsx b/src/journal-processors.tsx index 6ffa2a5..0da7570 100644 --- a/src/journal-processors.tsx +++ b/src/journal-processors.tsx @@ -6,8 +6,9 @@ import { EventType, ContactType } from './pim-types'; import * as EteSync from './api/EteSync'; -export function syncEntriesToItemMap(collection: EteSync.CollectionInfo, entries: List) { - let items: {[key: string]: ContactType} = {}; +export function syncEntriesToItemMap( + collection: EteSync.CollectionInfo, entries: List, base: {[key: string]: ContactType} = {}) { + let items = base; entries.forEach((syncEntry) => { let comp = new ContactType(new ICAL.Component(ICAL.parse(syncEntry.content))); @@ -49,8 +50,9 @@ function colorIntToHtml(color: number) { ((alpha > 0) ? toHex(alpha) : ''); } -export function syncEntriesToCalendarItemMap(collection: EteSync.CollectionInfo, entries: List) { - let items: {[key: string]: EventType} = {}; +export function syncEntriesToCalendarItemMap( + collection: EteSync.CollectionInfo, entries: List, base: {[key: string]: EventType} = {}) { + let items = base; const color = colorIntToHtml(collection.color);