diff src/app/services/feature-extraction/feature-extraction.service.ts @ 324:e433a2da0ada

Refactor the import library logic slightly to waterfall the loading of the libraries and list requests, and send one response when all libraries have been loaded.
author Lucas Thompson <dev@lucas.im>
date Tue, 16 May 2017 16:16:57 +0100
parents 98490d0ceb77
children e401995304a7
line wrap: on
line diff
--- a/src/app/services/feature-extraction/feature-extraction.service.ts	Tue May 16 11:15:43 2017 +0100
+++ b/src/app/services/feature-extraction/feature-extraction.service.ts	Tue May 16 16:16:57 2017 +0100
@@ -8,7 +8,7 @@
 } from 'piper/HigherLevelUtilities';
 import {Subject} from 'rxjs/Subject';
 import {Observable} from 'rxjs/Observable';
-import {Http, Response} from '@angular/http';
+import {Http} from '@angular/http';
 import {
   countingIdProvider,
   WebWorkerStreamingClient
@@ -63,7 +63,10 @@
   }
 
   list(): Promise<ListResponse> {
-    return this.client.list({});
+    return this.client.list({}).then(response => {
+      this.librariesUpdated.next(response);
+      return response;
+    });
   }
 
   extract(analysisItemId: string, request: SimpleRequest): Promise<void> {
@@ -87,20 +90,16 @@
     });
   }
 
-  updateAvailableLibraries(): Observable<AvailableLibraries> {
-    return this.http.get(this.repositoryUri)
-      .map(res => {
-        const map = res.json();
+  updateAvailableLibraries(): void {
+    this.http.get(this.repositoryUri)
+      .toPromise() // just turn into a promise for now to subscribe / execute
+      .then(res => {
         this.worker.postMessage({
           method: 'addRemoteLibraries',
-          params: map
-        });
-        return map;
+          params: res.json()
+        })
       })
-      .catch((error: Response | any) => {
-        console.error(error);
-        return Observable.throw(error);
-      });
+      .catch(console.error); // TODO Report error to user
   }
 
   load(libraryKey: string): void {