changeset 361:f12a12ce9de0

Change AnalysisItem type slightly to actually contain the feature data. Improve type guards a tad.
author Lucas Thompson <dev@lucas.im>
date Tue, 30 May 2017 15:07:32 +0100
parents 1ad3c86fd1f7
children bcb0a172eca3
files src/app/analysis-item/analysis-item.component.ts
diffstat 1 files changed, 17 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/app/analysis-item/analysis-item.component.ts	Tue May 30 15:06:37 2017 +0100
+++ b/src/app/analysis-item/analysis-item.component.ts	Tue May 30 15:07:32 2017 +0100
@@ -9,7 +9,10 @@
 } from '@angular/core';
 import {naivePagingMapper} from '../visualisations/WavesJunk';
 import {OnSeekHandler, TimePixelMapper} from '../playhead/PlayHeadHelpers';
-import {HigherLevelFeatureShape} from '../visualisations/FeatureUtilities';
+import {
+  HigherLevelFeatureShape,
+  KnownShapedFeature
+} from '../visualisations/FeatureUtilities';
 
 export interface Item {
   id: string;
@@ -31,12 +34,14 @@
   extractorKey: string;
 }
 
-export interface AnalysisItem extends PendingAnalysisItem {
-  kind: HigherLevelFeatureShape;
+export type AnalysisItem = PendingAnalysisItem & KnownShapedFeature;
+
+export function isItem(item: Item): item is Item {
+  return item.id != null && item.hasSharedTimeline != null;
 }
 
 export function isPendingRootAudioItem(item: Item): item is PendingRootAudioItem {
-  return typeof (item as RootAudioItem).uri === 'string';
+  return isItem(item) && typeof (item as RootAudioItem).uri === 'string';
 }
 
 export function isRootAudioItem(item: Item): item is RootAudioItem {
@@ -52,7 +57,9 @@
 
 export function isAnalysisItem(item: Item): item is AnalysisItem {
   const downcast = (item as AnalysisItem);
-  return isPendingAnalysisItem(item) && downcast.kind != null;
+  return isPendingAnalysisItem(item) &&
+    downcast.shape != null &&
+    downcast.collected != null;
 }
 
 // these should probably be actual concrete types with their own getUri methods
@@ -97,4 +104,9 @@
   isAudioItem(): boolean {
     return isRootAudioItem(this.item);
   }
+
+  getFeatureShape(): HigherLevelFeatureShape | null {
+    return !isPendingRootAudioItem(this.item) &&
+    isAnalysisItem(this.item) ? this.item.shape : null;
+  }
 }