changeset 282:5ab9e6132424

Create independent Timeline for each rootAudioUri, no idea how this was working before. Not sure if these belong here or in the application state, but this is better than before.
author Lucas Thompson <dev@lucas.im>
date Thu, 04 May 2017 15:21:52 +0100
parents 65ac5f8fc253
children a2ba82a51115
files src/app/notebook-feed/notebook-feed.component.html src/app/notebook-feed/notebook-feed.component.ts
diffstat 2 files changed, 17 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/app/notebook-feed/notebook-feed.component.html	Wed May 03 12:37:52 2017 +0100
+++ b/src/app/notebook-feed/notebook-feed.component.html	Thu May 04 15:21:52 2017 +0100
@@ -1,8 +1,7 @@
-
 <ng-template ngFor let-item [ngForOf]="analyses">
   <div [class.break]="item.isRoot">
     <ugly-analysis-item
-      [timeline]="item.hasSharedTimeline ? sharedTimeline : undefined"
+      [timeline]="getOrCreateTimeline(item)"
       [isActive]="rootAudioUri === item.rootAudioUri"
       [item]="item"
     ></ugly-analysis-item>
--- a/src/app/notebook-feed/notebook-feed.component.ts	Wed May 03 12:37:52 2017 +0100
+++ b/src/app/notebook-feed/notebook-feed.component.ts	Thu May 04 15:21:52 2017 +0100
@@ -16,23 +16,32 @@
   changeDetection: ChangeDetectionStrategy.OnPush
 })
 export class NotebookFeedComponent {
-  sharedTimeline: Timeline;
   @Input() analyses: AnalysisItem[];
   @Input() set rootAudioUri(uri: string) {
     this._rootAudioUri = uri;
-
-    // TODO is this safe? will the fact references are held elsewhere
-    // keep the previous instance alive? Or will it get garbage collected in
-    // screw previous layers up?
-    this.sharedTimeline = new Waves.core.Timeline();
   }
 
   get rootAudioUri(): string {
     return this._rootAudioUri;
   }
   private _rootAudioUri: string;
+  private timelines: Map<string, Timeline>;
 
   constructor() {
-    this.sharedTimeline = new Waves.core.Timeline();
+    this.timelines = new Map();
+  }
+
+  getOrCreateTimeline(item: AnalysisItem): Timeline | void {
+    if (!item.hasSharedTimeline) {
+      return;
+    }
+
+    if (this.timelines.has(item.rootAudioUri)) {
+      return this.timelines.get(item.rootAudioUri);
+    } else {
+      const timeline = new Waves.core.Timeline();
+      this.timelines.set(item.rootAudioUri, timeline);
+      return timeline;
+    }
   }
 }