diff src/app/services/feature-extraction/FeatureExtractionWorker.ts @ 248:4224929943bc

Small refactoring to avoid duplication of process and collect. It really seems like there is no need to have both methods.
author Lucas Thompson <dev@lucas.im>
date Thu, 27 Apr 2017 10:32:09 +0100
parents 7106cdd59e62
children 55be5d2e96f6
line wrap: on
line diff
--- a/src/app/services/feature-extraction/FeatureExtractionWorker.ts	Thu Apr 27 10:14:34 2017 +0100
+++ b/src/app/services/feature-extraction/FeatureExtractionWorker.ts	Thu Apr 27 10:32:09 2017 +0100
@@ -60,13 +60,18 @@
   }
 
   process(request: SimpleRequest): Observable<StreamingResponse> {
-    return undefined;
+    return this.dispatch('process', request);
   }
 
   collect(request: SimpleRequest): Observable<StreamingResponse> {
+    return this.dispatch('collect', request);
+  }
+
+  protected dispatch(method: 'process' | 'collect',
+                     request: SimpleRequest): Observable<StreamingResponse> {
     const key = request.key.split(':')[0];
     return this.services.has(key) ?
-      this.services.get(key).collect(request) : Observable.throw('Invalid key');
+      this.services.get(key)[method](request) : Observable.throw('Invalid key');
   }
 }
 
@@ -75,9 +80,10 @@
     super();
   }
 
-  collect(request: SimpleRequest): Observable<StreamingResponse> {
+  protected dispatch(method: 'process' | 'collect',
+                     request: SimpleRequest): Observable<StreamingResponse> {
     let lastPercentagePoint = 0;
-    return super.collect(request)
+    return super.dispatch(method, request)
       .scan(streamingResponseReducer)
       .filter(val => {
         const percentage =