@@ -2,12 +2,10 @@ import {FetchInstruction, Operation, VersionWorker} from './api';
22import {LOG} from './logging';
33import {VersionWorkerImpl} from './worker';
44
5- import {Observable} from 'rxjs/Observable';
6-
75export function cacheFromNetworkOp(worker: VersionWorker, url: string, cache: string): Operation {
86 const op: Operation = () => worker
97 .refresh(worker.adapter.newRequest(url))
10- .switchMap (resp => worker.cache.store(cache, url, resp));
8+ .then (resp => worker.cache.store(cache, url, resp));
119 op.desc = {type: 'cacheFromNetworkOp', worker, url, cache};
1210 return op;
1311}
@@ -16,20 +14,21 @@ export function copyExistingCacheOp(oldWorker: VersionWorker, newWorker: Version
1614 const op: Operation = () => oldWorker
1715 .cache
1816 .load(cache, url)
19- .switchMap (resp => !!resp
20- ? newWorker.cache.store(cache, url, resp)
21- : Observable.empty() );
17+ .then (resp => !!resp
18+ ? newWorker.cache.store(cache, url, resp).then(() => true)
19+ : null );
2220 op.desc = {type: 'copyExistingCacheOp', oldWorker, newWorker, url, cache};
2321 return op;
2422}
2523
2624export function copyExistingOrFetchOp(oldWorker: VersionWorker, newWorker: VersionWorker, url: string, cache: string): Operation {
27- const op: Operation = () => Observable
28- .concat(
29- copyExistingCacheOp(oldWorker, newWorker, url, cache)(),
30- cacheFromNetworkOp(newWorker, url, cache)()
31- )
32- .take(1);
25+ const op: Operation = () => copyExistingCacheOp(oldWorker, newWorker, url, cache)()
26+ .then(res => {
27+ if (!res) {
28+ return cacheFromNetworkOp(newWorker, url, cache)();
29+ }
30+ return res;
31+ });
3332 op.desc = {type: 'copyExistingOrFetchOp', oldWorker, newWorker, url, cache};
3433 return op;
3534}
@@ -41,24 +40,20 @@ export function deleteCacheOp(worker: VersionWorker, key: string): Operation {
4140}
4241
4342export function fetchFromCacheInstruction(worker: VersionWorker, req: string | Request, cache: string): FetchInstruction {
44- const op: FetchInstruction = () => worker
45- .cache
46- .load(cache, req)
47- .filter(v => !!v);
43+ const op: FetchInstruction = () => worker.cache.load(cache, req);
4844 op.desc = {type: 'fetchFromCacheInstruction', worker, req, cache};
4945 return op;
5046}
5147
5248export function fetchFromNetworkInstruction(worker: VersionWorker, req: Request, shouldRefresh: boolean = true): FetchInstruction {
53- const op: FetchInstruction = () => shouldRefresh ? worker.refresh(req) : (worker as VersionWorkerImpl).scope.fetch(req);
49+ const op: FetchInstruction = () => shouldRefresh ? worker.refresh(req) : (worker as any as VersionWorkerImpl).scope.fetch(req);
5450 op.desc = {type: 'fetchFromNetworkInstruction', worker, req};
5551 return op;
5652}
5753
5854export function rewriteUrlInstruction(worker: VersionWorker, req: Request, destUrl: string): FetchInstruction {
5955 const newReq = worker.adapter.newRequest(destUrl);
60- const op: FetchInstruction = () => worker
61- .fetch(newReq);
56+ const op: FetchInstruction = () => worker.fetch(newReq);
6257 op.desc = {type: 'rewriteUrlInstruction', worker, req, destUrl};
6358 return op;
6459}
0 commit comments