changeset 19:953932e9ba82

Remove zone injection from app.component and move to where the event is emitted in audio-file-open.component.
author Lucas Thompson <dev@lucas.im>
date Fri, 28 Oct 2016 08:28:54 +0100
parents dcfcba8fde0a
children aabfa7a693dc
files src/app/app.component.ts src/app/audio-file-open/audio-file-open.component.ts
diffstat 2 files changed, 9 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/app/app.component.ts	Thu Oct 27 17:48:23 2016 +0100
+++ b/src/app/app.component.ts	Fri Oct 28 08:28:54 2016 +0100
@@ -1,4 +1,4 @@
-import {Component, Inject, NgZone} from '@angular/core';
+import {Component, Inject} from '@angular/core';
 import {MailService} from "./mail.service";
 
 @Component({
@@ -14,8 +14,7 @@
 
   constructor(
     private mail: MailService,
-    @Inject('piper-server-uri') private serverUri,
-    private zone: NgZone
+    @Inject('piper-server-uri') private serverUri
   ) {}
 
   onUpdate(id, text) {
@@ -23,10 +22,8 @@
   }
 
   onAudioLoaded(buffer: AudioBuffer) {
-    this.zone.run(() => { // TODO why the f does this only recognise changes immediately (and not the next tick) inside zone.run?
-      this.audioBuffer = buffer;
-      this.count++;
-    });
+    this.audioBuffer = buffer;
+    this.count++;
   }
 
   testRef() {
--- a/src/app/audio-file-open/audio-file-open.component.ts	Thu Oct 27 17:48:23 2016 +0100
+++ b/src/app/audio-file-open/audio-file-open.component.ts	Fri Oct 28 08:28:54 2016 +0100
@@ -1,6 +1,6 @@
 import {
   Component, OnInit, ViewChild, ElementRef, Output,
-  EventEmitter
+  EventEmitter, NgZone
 } from '@angular/core';
 
 interface AudioContextConstructor {
@@ -24,7 +24,7 @@
 
   private audioContext: AudioContext;
 
-  constructor() {
+  constructor(private zone: NgZone) {
     this.audioLoaded = new EventEmitter<AudioBuffer>();
 
     // TODO make a service which provides the AudioContext?
@@ -40,7 +40,9 @@
       const reader: FileReader = new FileReader();
       reader.onload = (event: any) => {
         this.audioContext.decodeAudioData(event.target.result, buffer => {
-          this.audioLoaded.emit(buffer);
+          this.zone.run(() => {
+            this.audioLoaded.emit(buffer);
+          });
         });
       };
       reader.readAsArrayBuffer(files[0]);