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.
master
Tom Hacohen 7 years ago
parent 70486e7da2
commit c945731d8a

@ -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<string, ContactType>,
entries: {[key: string]: ContactType},
history?: any,
};
@ -38,7 +42,7 @@ class JournalAddressBook extends React.Component {
path={routeResolver.getRoute('journals._id')}
exact={true}
render={() => (
<AddressBook entries={Array.from(items.values())} onItemClick={this.contactClicked} />
<AddressBook entries={objValues(items)} onItemClick={this.contactClicked} />
)
}
/>
@ -48,7 +52,7 @@ class JournalAddressBook extends React.Component {
render={({match}) => {
return (
<Contact contact={items.get(match.params.itemUid)} />
<Contact contact={items[match.params.itemUid]} />
);
}}
/>

@ -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<string, EventType>,
entries: {[key: string]: EventType},
history?: any,
};
@ -41,7 +45,7 @@ class JournalCalendar extends React.Component {
path={routeResolver.getRoute('journals._id')}
exact={true}
render={() => (
<PersistCalendar entries={Array.from(items.values())} onItemClick={this.eventClicked} />
<PersistCalendar entries={objValues(items)} onItemClick={this.eventClicked} />
)
}
/>
@ -49,7 +53,7 @@ class JournalCalendar extends React.Component {
path={routeResolver.getRoute('journals._id.items._id')}
exact={true}
render={({match}) => (
<Event event={items.get(match.params.itemUid)} />
<Event event={items[match.params.itemUid]} />
)}
/>
</Switch>

@ -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}) => (
<PimMain
contacts={Array.from(addressBookItems.values())}
events={Array.from(calendarItems.values())}
contacts={objValues(addressBookItems)}
events={objValues(calendarItems)}
history={history}
/>
)}
@ -85,7 +89,7 @@ class Pim extends React.Component {
exact={true}
render={({match}) => (
<Container>
<Contact contact={addressBookItems.get(match.params.contactUid)} />
<Contact contact={addressBookItems[match.params.contactUid]} />
</Container>
)}
/>
@ -94,7 +98,7 @@ class Pim extends React.Component {
exact={true}
render={({match}) => (
<Container>
<Event event={calendarItems.get(match.params.eventUid)} />
<Event event={calendarItems[match.params.eventUid]} />
</Container>
)}
/>

@ -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<string, ContactType> = 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<string, EventType> = 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];
}
}

Loading…
Cancel
Save