Reputation: 77
Moved to angular8, rxjs6. timer, switchMap, combineLatest, methods breaking. Trying to solve combineLatest or Timer propeties breaks the flow of the other properties.
Initialy code breaks at Partition, fixed it error TS2339: Property 'partition' does not exist on type 'Observable<boolean>'
init(): void {
const source = this.store.select(state => state.tether.isTiming);
const partition = (predicate) => [source.pipe(filter(predicate)), source.pipe(filter((x, i) => !predicate(x, i)))]
const [isTiming$, isNotTiming$] = partition(value => value);
const partialInterval$ = this.store.select(state => state.tether.partialInterval);
const interval$ = this.store.select(state => state.tether.interval);
isTiming$
.combineLatest(interval$, (isTiming, interval) => interval)
.withLatestFrom(partialInterval$)
.switchMap(([interval, partialInterval]) => {
return timer(partialInterval, interval)
.takeUntil(isNotTiming$);
})
.subscribe(() => {
this.store.dispatch(softDrop(true));
});
}
rewriting this with piping breaks.
isTiming$
.combineLatest(interval$, (isTiming, interval) => interval)
.withLatestFrom(partialInterval$)
.switchMap(([interval, partialInterval]) => {
return timer(partialInterval, interval)
.takeUntil(isNotTiming$);
})
.subscribe(() => {
this.store.dispatch(softDrop(true));
});
error TS2339: Property 'timer' does not exist on type 'typeof Observable'.
error TS2339: Property 'combineLatest' does not exist on type 'Observable'.
error TS2339: Property 'withLatestFrom' does not exist on type 'Observable'.
Upvotes: 0
Views: 2324
Reputation: 9355
Now in new RX-6 timer
and combineLatest
is now part of rxjs core module and withLatestFrom
is available under rxjs/operators
module
See: timer, combineLatest and withLatestFrom
In your case following implementation will work
init(): void {
const source = this.store.select(state => state.tetris.isTiming);
const partition = (predicate) => [source.pipe(filter(predicate)), source.pipe(filter((x, i) => !predicate(x, i)))]
const [isTiming$, isNotTiming$] = partition(value => value);
const partialInterval$ = this.store.select(state => state.tetris.partialInterval);
const interval$ = this.store.select(state => state.tetris.interval);
combineLatest(interval$, (isTiming, interval) => interval).pipe(
withLatestFrom(partialInterval$), switchMap(([interval, partialInterval]) => {
return timer(partialInterval, 1000).pipe(takeUntil(isNotTiming$));
})
)
.subscribe(() => {
this.store.dispatch(softDrop(true));
});
}
Upvotes: 1