view src/app/notebook-feed/notebook-feed.component.ts @ 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 53ea6406d601
children 2d7da410ba46
line wrap: on
line source
/**
 * Created by lucast on 21/03/2017.
 */
import {
  ChangeDetectionStrategy,
  Component,
  Input
} from '@angular/core';
import Waves from 'waves-ui';
import {AnalysisItem} from '../analysis-item/analysis-item.component';

@Component({
  selector: 'ugly-notebook-feed',
  templateUrl: './notebook-feed.component.html',
  styleUrls: ['./notebook-feed.component.css'],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class NotebookFeedComponent {
  @Input() analyses: AnalysisItem[];
  @Input() set rootAudioUri(uri: string) {
    this._rootAudioUri = uri;
  }

  get rootAudioUri(): string {
    return this._rootAudioUri;
  }
  private _rootAudioUri: string;
  private timelines: Map<string, Timeline>;

  constructor() {
    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;
    }
  }
}