From c945731d8a5f98993cf2a3a0f403dfcf1aae821b Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Fri, 8 Dec 2017 20:15:13 +0000 Subject: [PATCH] Stop using Map<>. It looks like this is more trouble than its worth. Things are missing and it's in general a pain to work with. --- src/JournalAddressBook.tsx | 10 +++++++--- src/JournalCalendar.tsx | 10 +++++++--- src/Pim.tsx | 12 ++++++++---- src/journal-processors.tsx | 12 ++++++------ 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/JournalAddressBook.tsx b/src/JournalAddressBook.tsx index b2ba572..583d511 100644 --- a/src/JournalAddressBook.tsx +++ b/src/JournalAddressBook.tsx @@ -10,10 +10,14 @@ import Contact from './Contact'; import { ContactType } from './pim-types'; +function objValues(obj: any) { + return Object.keys(obj).map((x) => obj[x]); +} + class JournalAddressBook extends React.Component { props: { journal: EteSync.Journal, - entries: Map, + entries: {[key: string]: ContactType}, history?: any, }; @@ -38,7 +42,7 @@ class JournalAddressBook extends React.Component { path={routeResolver.getRoute('journals._id')} exact={true} render={() => ( - + ) } /> @@ -48,7 +52,7 @@ class JournalAddressBook extends React.Component { render={({match}) => { return ( - + ); }} /> diff --git a/src/JournalCalendar.tsx b/src/JournalCalendar.tsx index 2f35f4a..2569a98 100644 --- a/src/JournalCalendar.tsx +++ b/src/JournalCalendar.tsx @@ -12,10 +12,14 @@ import { EventType } from './pim-types'; import * as EteSync from './api/EteSync'; +function objValues(obj: any) { + return Object.keys(obj).map((x) => obj[x]); +} + class JournalCalendar extends React.Component { props: { journal: EteSync.Journal, - entries: Map, + entries: {[key: string]: EventType}, history?: any, }; @@ -41,7 +45,7 @@ class JournalCalendar extends React.Component { path={routeResolver.getRoute('journals._id')} exact={true} render={() => ( - + ) } /> @@ -49,7 +53,7 @@ class JournalCalendar extends React.Component { path={routeResolver.getRoute('journals._id.items._id')} exact={true} render={({match}) => ( - + )} /> diff --git a/src/Pim.tsx b/src/Pim.tsx index 1868ad5..5d75a04 100644 --- a/src/Pim.tsx +++ b/src/Pim.tsx @@ -15,6 +15,10 @@ import { JournalsData, EntriesType, CredentialsData } from './store'; import { syncEntriesToItemMap, syncEntriesToCalendarItemMap } from './journal-processors'; +function objValues(obj: any) { + return Object.keys(obj).map((x) => obj[x]); +} + class Pim extends React.Component { props: { etesync: CredentialsData; @@ -74,8 +78,8 @@ class Pim extends React.Component { exact={true} render={({history}) => ( )} @@ -85,7 +89,7 @@ class Pim extends React.Component { exact={true} render={({match}) => ( - + )} /> @@ -94,7 +98,7 @@ class Pim extends React.Component { exact={true} render={({match}) => ( - + )} /> diff --git a/src/journal-processors.tsx b/src/journal-processors.tsx index a7890cf..3ecc0c2 100644 --- a/src/journal-processors.tsx +++ b/src/journal-processors.tsx @@ -5,7 +5,7 @@ import { EventType, ContactType } from './pim-types'; import * as EteSync from './api/EteSync'; export function syncEntriesToItemMap(entries: EteSync.SyncEntry[]) { - let items: Map = new Map(); + let items: {[key: string]: ContactType} = {}; for (const syncEntry of entries) { let comp = new ContactType(new ICAL.Component(ICAL.parse(syncEntry.content))); @@ -14,9 +14,9 @@ export function syncEntriesToItemMap(entries: EteSync.SyncEntry[]) { if ((syncEntry.action === EteSync.SyncEntryAction.Add) || (syncEntry.action === EteSync.SyncEntryAction.Change)) { - items.set(uid, comp); + items[uid] = comp; } else if (syncEntry.action === EteSync.SyncEntryAction.Delete) { - items.delete(uid); + delete items[uid]; } } @@ -24,7 +24,7 @@ export function syncEntriesToItemMap(entries: EteSync.SyncEntry[]) { } export function syncEntriesToCalendarItemMap(entries: EteSync.SyncEntry[]) { - let items: Map = new Map(); + let items: {[key: string]: EventType} = {}; for (const syncEntry of entries) { let comp = new EventType(new ICAL.Component(ICAL.parse(syncEntry.content)).getFirstSubcomponent('vevent')); @@ -37,9 +37,9 @@ export function syncEntriesToCalendarItemMap(entries: EteSync.SyncEntry[]) { if ((syncEntry.action === EteSync.SyncEntryAction.Add) || (syncEntry.action === EteSync.SyncEntryAction.Change)) { - items.set(uid, comp); + items[uid] = comp; } else if (syncEntry.action === EteSync.SyncEntryAction.Delete) { - items.delete(uid); + delete items[uid]; } }