From 074fc8e6c0984c70c1d672785c0fbb1370541b81 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Thu, 28 Dec 2017 17:42:59 +0000 Subject: [PATCH] Implement a common interface for pim types. --- src/Pim/index.tsx | 14 +++++++------- src/pim-types.ts | 10 ++++++++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/Pim/index.tsx b/src/Pim/index.tsx index e8fa807..f68dc3c 100644 --- a/src/Pim/index.tsx +++ b/src/Pim/index.tsx @@ -13,7 +13,7 @@ import { pure } from 'recompose'; import { History } from 'history'; -import { ContactType, EventType } from '../pim-types'; +import { PimType, ContactType, EventType } from '../pim-types'; import Container from '../widgets/Container'; @@ -72,7 +72,7 @@ const ItemChangeLog = pure((props: any) => { uid, } = props; - const journalItem = syncInfo.get((items[uid] as any).journalUid); + const journalItem = syncInfo.get(items[uid].journalUid); return ( @@ -94,9 +94,9 @@ const CollectionRoutes = withRouter( collections: Array, componentEdit: any, componentView: any, - items: {[key: string]: any}, - onItemSave: (item: Object, journalUid: string, originalContact?: Object) => void; - onItemDelete: (item: Object, journalUid: string) => void; + items: {[key: string]: PimType}, + onItemSave: (item: PimType, journalUid: string, originalContact?: PimType) => void; + onItemDelete: (item: PimType, journalUid: string) => void; onItemCancel: () => void; }; @@ -204,7 +204,7 @@ class Pim extends React.PureComponent { this.onItemSave = this.onItemSave.bind(this); } - onItemSave(item: any, journalUid: string, originalEvent?: any) { + onItemSave(item: PimType, journalUid: string, originalEvent?: PimType) { const syncJournal = this.props.syncInfo.get(journalUid); if (syncJournal === undefined) { @@ -221,7 +221,7 @@ class Pim extends React.PureComponent { }); } - onItemDelete(item: any, journalUid: string) { + onItemDelete(item: PimType, journalUid: string) { const syncJournal = this.props.syncInfo.get(journalUid); if (syncJournal === undefined) { diff --git a/src/pim-types.ts b/src/pim-types.ts index 44b116a..e84a0cf 100644 --- a/src/pim-types.ts +++ b/src/pim-types.ts @@ -1,6 +1,12 @@ import * as ICAL from 'ical.js'; -export class EventType extends ICAL.Event { +export interface PimType { + uid: string; + toIcal(): string; + clone(): PimType; +} + +export class EventType extends ICAL.Event implements PimType { color: string; static fromVCalendar(comp: ICAL.Component) { @@ -33,7 +39,7 @@ export class EventType extends ICAL.Event { } } -export class ContactType { +export class ContactType implements PimType { comp: ICAL.Component; constructor(comp: ICAL.Component) {