comparison src/app/analysis-item/analysis-item.component.ts @ 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 2453773eddd6
children 9fe6e00e0700
comparison
equal deleted inserted replaced
360:1ad3c86fd1f7 361:f12a12ce9de0
7 Input, 7 Input,
8 OnInit 8 OnInit
9 } from '@angular/core'; 9 } from '@angular/core';
10 import {naivePagingMapper} from '../visualisations/WavesJunk'; 10 import {naivePagingMapper} from '../visualisations/WavesJunk';
11 import {OnSeekHandler, TimePixelMapper} from '../playhead/PlayHeadHelpers'; 11 import {OnSeekHandler, TimePixelMapper} from '../playhead/PlayHeadHelpers';
12 import {HigherLevelFeatureShape} from '../visualisations/FeatureUtilities'; 12 import {
13 HigherLevelFeatureShape,
14 KnownShapedFeature
15 } from '../visualisations/FeatureUtilities';
13 16
14 export interface Item { 17 export interface Item {
15 id: string; 18 id: string;
16 hasSharedTimeline: boolean; 19 hasSharedTimeline: boolean;
17 title?: string; 20 title?: string;
29 export interface PendingAnalysisItem extends Item { 32 export interface PendingAnalysisItem extends Item {
30 parent: RootAudioItem; 33 parent: RootAudioItem;
31 extractorKey: string; 34 extractorKey: string;
32 } 35 }
33 36
34 export interface AnalysisItem extends PendingAnalysisItem { 37 export type AnalysisItem = PendingAnalysisItem & KnownShapedFeature;
35 kind: HigherLevelFeatureShape; 38
39 export function isItem(item: Item): item is Item {
40 return item.id != null && item.hasSharedTimeline != null;
36 } 41 }
37 42
38 export function isPendingRootAudioItem(item: Item): item is PendingRootAudioItem { 43 export function isPendingRootAudioItem(item: Item): item is PendingRootAudioItem {
39 return typeof (item as RootAudioItem).uri === 'string'; 44 return isItem(item) && typeof (item as RootAudioItem).uri === 'string';
40 } 45 }
41 46
42 export function isRootAudioItem(item: Item): item is RootAudioItem { 47 export function isRootAudioItem(item: Item): item is RootAudioItem {
43 return isPendingRootAudioItem(item) && 48 return isPendingRootAudioItem(item) &&
44 (item as RootAudioItem).audioData instanceof AudioBuffer; 49 (item as RootAudioItem).audioData instanceof AudioBuffer;
50 && typeof downcast.extractorKey === 'string'; 55 && typeof downcast.extractorKey === 'string';
51 } 56 }
52 57
53 export function isAnalysisItem(item: Item): item is AnalysisItem { 58 export function isAnalysisItem(item: Item): item is AnalysisItem {
54 const downcast = (item as AnalysisItem); 59 const downcast = (item as AnalysisItem);
55 return isPendingAnalysisItem(item) && downcast.kind != null; 60 return isPendingAnalysisItem(item) &&
61 downcast.shape != null &&
62 downcast.collected != null;
56 } 63 }
57 64
58 // these should probably be actual concrete types with their own getUri methods 65 // these should probably be actual concrete types with their own getUri methods
59 export function getRootUri(item: Item): string { 66 export function getRootUri(item: Item): string {
60 if (isPendingRootAudioItem(item)) { 67 if (isPendingRootAudioItem(item)) {
95 } 102 }
96 103
97 isAudioItem(): boolean { 104 isAudioItem(): boolean {
98 return isRootAudioItem(this.item); 105 return isRootAudioItem(this.item);
99 } 106 }
107
108 getFeatureShape(): HigherLevelFeatureShape | null {
109 return !isPendingRootAudioItem(this.item) &&
110 isAnalysisItem(this.item) ? this.item.shape : null;
111 }
100 } 112 }