Mercurial > hg > ugly-duckling
comparison 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 |
comparison
equal
deleted
inserted
replaced
247:7a6ef711c73a | 248:4224929943bc |
---|---|
58 }) | 58 }) |
59 ); | 59 ); |
60 } | 60 } |
61 | 61 |
62 process(request: SimpleRequest): Observable<StreamingResponse> { | 62 process(request: SimpleRequest): Observable<StreamingResponse> { |
63 return undefined; | 63 return this.dispatch('process', request); |
64 } | 64 } |
65 | 65 |
66 collect(request: SimpleRequest): Observable<StreamingResponse> { | 66 collect(request: SimpleRequest): Observable<StreamingResponse> { |
67 return this.dispatch('collect', request); | |
68 } | |
69 | |
70 protected dispatch(method: 'process' | 'collect', | |
71 request: SimpleRequest): Observable<StreamingResponse> { | |
67 const key = request.key.split(':')[0]; | 72 const key = request.key.split(':')[0]; |
68 return this.services.has(key) ? | 73 return this.services.has(key) ? |
69 this.services.get(key).collect(request) : Observable.throw('Invalid key'); | 74 this.services.get(key)[method](request) : Observable.throw('Invalid key'); |
70 } | 75 } |
71 } | 76 } |
72 | 77 |
73 class ReducingAggregateService extends AggregateStreamingService { | 78 class ReducingAggregateService extends AggregateStreamingService { |
74 constructor() { | 79 constructor() { |
75 super(); | 80 super(); |
76 } | 81 } |
77 | 82 |
78 collect(request: SimpleRequest): Observable<StreamingResponse> { | 83 protected dispatch(method: 'process' | 'collect', |
84 request: SimpleRequest): Observable<StreamingResponse> { | |
79 let lastPercentagePoint = 0; | 85 let lastPercentagePoint = 0; |
80 return super.collect(request) | 86 return super.dispatch(method, request) |
81 .scan(streamingResponseReducer) | 87 .scan(streamingResponseReducer) |
82 .filter(val => { | 88 .filter(val => { |
83 const percentage = | 89 const percentage = |
84 100 * (val.processedBlockCount / val.totalBlockCount) | 0; | 90 100 * (val.processedBlockCount / val.totalBlockCount) | 0; |
85 const pointDifference = (percentage - lastPercentagePoint); | 91 const pointDifference = (percentage - lastPercentagePoint); |