annotate src/app/notebook-feed/notebook-feed.component.ts @ 289:6a83df5029fe

Use our waves-ui fork.
author Lucas Thompson <dev@lucas.im>
date Fri, 05 May 2017 14:58:22 +0100
parents 2d7da410ba46
children d17d5038b11a
rev   line source
dev@171 1 /**
dev@171 2 * Created by lucast on 21/03/2017.
dev@171 3 */
dev@232 4 import {
dev@232 5 ChangeDetectionStrategy,
dev@285 6 ChangeDetectorRef,
dev@232 7 Component,
dev@285 8 Inject,
dev@285 9 Input,
dev@285 10 OnDestroy
dev@236 11 } from '@angular/core';
dev@289 12 import Waves from 'waves-ui-piper';
dev@236 13 import {AnalysisItem} from '../analysis-item/analysis-item.component';
dev@285 14 import {Observable} from 'rxjs/Observable';
dev@285 15 import {Dimension} from '../app.module';
dev@285 16 import {Subscription} from 'rxjs/Subscription';
dev@171 17
dev@171 18 @Component({
dev@171 19 selector: 'ugly-notebook-feed',
dev@171 20 templateUrl: './notebook-feed.component.html',
dev@232 21 styleUrls: ['./notebook-feed.component.css'],
dev@232 22 changeDetection: ChangeDetectionStrategy.OnPush
dev@171 23 })
dev@285 24 export class NotebookFeedComponent implements OnDestroy {
dev@201 25 @Input() analyses: AnalysisItem[];
dev@201 26 @Input() set rootAudioUri(uri: string) {
dev@201 27 this._rootAudioUri = uri;
dev@171 28 }
dev@171 29
dev@201 30 get rootAudioUri(): string {
dev@201 31 return this._rootAudioUri;
dev@171 32 }
dev@201 33 private _rootAudioUri: string;
dev@285 34 private resizeSubscription: Subscription;
dev@285 35 private width: number;
dev@285 36 private lastWidth: number;
dev@282 37 private timelines: Map<string, Timeline>;
dev@181 38
dev@285 39 constructor(
dev@285 40 private ref: ChangeDetectorRef,
dev@285 41 @Inject('DimensionObservable') private onResize: Observable<Dimension>
dev@285 42 ) {
dev@282 43 this.timelines = new Map();
dev@285 44 this.onResize.subscribe(dim => {
dev@285 45 this.lastWidth = this.width;
dev@285 46 this.width = dim.width;
dev@285 47 });
dev@285 48
dev@285 49 // the use of requestAnimationFrame here is to leave the dom updates
dev@285 50 // to a time convenient for the browser, and avoid a cascade / waterfall
dev@285 51 // of DOM changes for rapid resize events in the event handler above.
dev@285 52 // ..I'm not convinced this is particularly beneficial here // TODO
dev@285 53 const triggerChangeDetectionOnResize = () => {
dev@285 54 requestAnimationFrame(triggerChangeDetectionOnResize);
dev@285 55 if (this.width !== this.lastWidth) {
dev@285 56 ref.markForCheck(); // only trigger change detection if width changed
dev@285 57 }
dev@285 58 };
dev@285 59 requestAnimationFrame(triggerChangeDetectionOnResize);
dev@282 60 }
dev@282 61
dev@282 62 getOrCreateTimeline(item: AnalysisItem): Timeline | void {
dev@282 63 if (!item.hasSharedTimeline) {
dev@282 64 return;
dev@282 65 }
dev@282 66
dev@282 67 if (this.timelines.has(item.rootAudioUri)) {
dev@282 68 return this.timelines.get(item.rootAudioUri);
dev@282 69 } else {
dev@282 70 const timeline = new Waves.core.Timeline();
dev@282 71 this.timelines.set(item.rootAudioUri, timeline);
dev@282 72 return timeline;
dev@282 73 }
dev@181 74 }
dev@285 75
dev@285 76 ngOnDestroy(): void {
dev@285 77 if (this.resizeSubscription) {
dev@285 78 this.resizeSubscription.unsubscribe();
dev@285 79 }
dev@285 80 }
dev@171 81 }