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'; import { ContactType } from './pim-types';
function objValues(obj: any) {
return Object.keys(obj).map((x) => obj[x]);
}
class JournalAddressBook extends React.Component { class JournalAddressBook extends React.Component {
props: { props: {
journal: EteSync.Journal, journal: EteSync.Journal,
entries: Map<string, ContactType>, entries: {[key: string]: ContactType},
history?: any, history?: any,
}; };
@ -38,7 +42,7 @@ class JournalAddressBook extends React.Component {
path={routeResolver.getRoute('journals._id')} path={routeResolver.getRoute('journals._id')}
exact={true} exact={true}
render={() => ( 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}) => { render={({match}) => {
return ( 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'; import * as EteSync from './api/EteSync';
function objValues(obj: any) {
return Object.keys(obj).map((x) => obj[x]);
}
class JournalCalendar extends React.Component { class JournalCalendar extends React.Component {
props: { props: {
journal: EteSync.Journal, journal: EteSync.Journal,
entries: Map<string, EventType>, entries: {[key: string]: EventType},
history?: any, history?: any,
}; };
@ -41,7 +45,7 @@ class JournalCalendar extends React.Component {
path={routeResolver.getRoute('journals._id')} path={routeResolver.getRoute('journals._id')}
exact={true} exact={true}
render={() => ( 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')} path={routeResolver.getRoute('journals._id.items._id')}
exact={true} exact={true}
render={({match}) => ( render={({match}) => (
<Event event={items.get(match.params.itemUid)} /> <Event event={items[match.params.itemUid]} />
)} )}
/> />
</Switch> </Switch>

@ -15,6 +15,10 @@ import { JournalsData, EntriesType, CredentialsData } from './store';
import { syncEntriesToItemMap, syncEntriesToCalendarItemMap } from './journal-processors'; import { syncEntriesToItemMap, syncEntriesToCalendarItemMap } from './journal-processors';
function objValues(obj: any) {
return Object.keys(obj).map((x) => obj[x]);
}
class Pim extends React.Component { class Pim extends React.Component {
props: { props: {
etesync: CredentialsData; etesync: CredentialsData;
@ -74,8 +78,8 @@ class Pim extends React.Component {
exact={true} exact={true}
render={({history}) => ( render={({history}) => (
<PimMain <PimMain
contacts={Array.from(addressBookItems.values())} contacts={objValues(addressBookItems)}
events={Array.from(calendarItems.values())} events={objValues(calendarItems)}
history={history} history={history}
/> />
)} )}
@ -85,7 +89,7 @@ class Pim extends React.Component {
exact={true} exact={true}
render={({match}) => ( render={({match}) => (
<Container> <Container>
<Contact contact={addressBookItems.get(match.params.contactUid)} /> <Contact contact={addressBookItems[match.params.contactUid]} />
</Container> </Container>
)} )}
/> />
@ -94,7 +98,7 @@ class Pim extends React.Component {
exact={true} exact={true}
render={({match}) => ( render={({match}) => (
<Container> <Container>
<Event event={calendarItems.get(match.params.eventUid)} /> <Event event={calendarItems[match.params.eventUid]} />
</Container> </Container>
)} )}
/> />

@ -5,7 +5,7 @@ import { EventType, ContactType } from './pim-types';
import * as EteSync from './api/EteSync'; import * as EteSync from './api/EteSync';
export function syncEntriesToItemMap(entries: EteSync.SyncEntry[]) { export function syncEntriesToItemMap(entries: EteSync.SyncEntry[]) {
let items: Map<string, ContactType> = new Map(); let items: {[key: string]: ContactType} = {};
for (const syncEntry of entries) { for (const syncEntry of entries) {
let comp = new ContactType(new ICAL.Component(ICAL.parse(syncEntry.content))); 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) || if ((syncEntry.action === EteSync.SyncEntryAction.Add) ||
(syncEntry.action === EteSync.SyncEntryAction.Change)) { (syncEntry.action === EteSync.SyncEntryAction.Change)) {
items.set(uid, comp); items[uid] = comp;
} else if (syncEntry.action === EteSync.SyncEntryAction.Delete) { } 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[]) { export function syncEntriesToCalendarItemMap(entries: EteSync.SyncEntry[]) {
let items: Map<string, EventType> = new Map(); let items: {[key: string]: EventType} = {};
for (const syncEntry of entries) { for (const syncEntry of entries) {
let comp = new EventType(new ICAL.Component(ICAL.parse(syncEntry.content)).getFirstSubcomponent('vevent')); 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) || if ((syncEntry.action === EteSync.SyncEntryAction.Add) ||
(syncEntry.action === EteSync.SyncEntryAction.Change)) { (syncEntry.action === EteSync.SyncEntryAction.Change)) {
items.set(uid, comp); items[uid] = comp;
} else if (syncEntry.action === EteSync.SyncEntryAction.Delete) { } else if (syncEntry.action === EteSync.SyncEntryAction.Delete) {
items.delete(uid); delete items[uid];
} }
} }

Loading…
Cancel
Save