ZipWithLatestForm *Wanted Operator* or Workaround
up vote
1
down vote
favorite
Lets consider following streams:
Stream1: 1 2 3 4 5 6 7 8 9
Stream2: ab c d f
Output I would like to get with combining these streams:
[1, a]
[2, b]
[3, c]
[4, c]
[5, d]
[6, f]
[7, f]
[8, f]
[9, f]
Sample Code Idea: StackBlitz Editor Link
const input$ = fromEvent(document, 'keydown')
.pipe(
map((event: KeyboardEvent) => event.keyCode)
);
const source$ = interval(500).pipe(s$ => zip(s$, input$))
source$.subscribe(x => console.log(x));
So this is something like operators zip() and/or withLatestForm(), but I can't come up with solution
- Main idea is that I have interval of 500ms and on every tick I want to zip it with Keyboard Input Observable, which works how I would like, but as long I am not emitting Keyboard Input Observable everything stops. I want to keep emitting interval ticks, but if keyboard events stop then take the latest value
javascript typescript rxjs reactive-programming rxjs6
add a comment |
up vote
1
down vote
favorite
Lets consider following streams:
Stream1: 1 2 3 4 5 6 7 8 9
Stream2: ab c d f
Output I would like to get with combining these streams:
[1, a]
[2, b]
[3, c]
[4, c]
[5, d]
[6, f]
[7, f]
[8, f]
[9, f]
Sample Code Idea: StackBlitz Editor Link
const input$ = fromEvent(document, 'keydown')
.pipe(
map((event: KeyboardEvent) => event.keyCode)
);
const source$ = interval(500).pipe(s$ => zip(s$, input$))
source$.subscribe(x => console.log(x));
So this is something like operators zip() and/or withLatestForm(), but I can't come up with solution
- Main idea is that I have interval of 500ms and on every tick I want to zip it with Keyboard Input Observable, which works how I would like, but as long I am not emitting Keyboard Input Observable everything stops. I want to keep emitting interval ticks, but if keyboard events stop then take the latest value
javascript typescript rxjs reactive-programming rxjs6
Does the output at the beginning of your question actually represent your use case? I'm not at all sure that it does. In which case, there are two questions within your question.
– cartant
3 hours ago
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
Lets consider following streams:
Stream1: 1 2 3 4 5 6 7 8 9
Stream2: ab c d f
Output I would like to get with combining these streams:
[1, a]
[2, b]
[3, c]
[4, c]
[5, d]
[6, f]
[7, f]
[8, f]
[9, f]
Sample Code Idea: StackBlitz Editor Link
const input$ = fromEvent(document, 'keydown')
.pipe(
map((event: KeyboardEvent) => event.keyCode)
);
const source$ = interval(500).pipe(s$ => zip(s$, input$))
source$.subscribe(x => console.log(x));
So this is something like operators zip() and/or withLatestForm(), but I can't come up with solution
- Main idea is that I have interval of 500ms and on every tick I want to zip it with Keyboard Input Observable, which works how I would like, but as long I am not emitting Keyboard Input Observable everything stops. I want to keep emitting interval ticks, but if keyboard events stop then take the latest value
javascript typescript rxjs reactive-programming rxjs6
Lets consider following streams:
Stream1: 1 2 3 4 5 6 7 8 9
Stream2: ab c d f
Output I would like to get with combining these streams:
[1, a]
[2, b]
[3, c]
[4, c]
[5, d]
[6, f]
[7, f]
[8, f]
[9, f]
Sample Code Idea: StackBlitz Editor Link
const input$ = fromEvent(document, 'keydown')
.pipe(
map((event: KeyboardEvent) => event.keyCode)
);
const source$ = interval(500).pipe(s$ => zip(s$, input$))
source$.subscribe(x => console.log(x));
So this is something like operators zip() and/or withLatestForm(), but I can't come up with solution
- Main idea is that I have interval of 500ms and on every tick I want to zip it with Keyboard Input Observable, which works how I would like, but as long I am not emitting Keyboard Input Observable everything stops. I want to keep emitting interval ticks, but if keyboard events stop then take the latest value
javascript typescript rxjs reactive-programming rxjs6
javascript typescript rxjs reactive-programming rxjs6
edited 4 hours ago
chazsolo
4,8921232
4,8921232
asked 4 hours ago
Goga Koreli
1139
1139
Does the output at the beginning of your question actually represent your use case? I'm not at all sure that it does. In which case, there are two questions within your question.
– cartant
3 hours ago
add a comment |
Does the output at the beginning of your question actually represent your use case? I'm not at all sure that it does. In which case, there are two questions within your question.
– cartant
3 hours ago
Does the output at the beginning of your question actually represent your use case? I'm not at all sure that it does. In which case, there are two questions within your question.
– cartant
3 hours ago
Does the output at the beginning of your question actually represent your use case? I'm not at all sure that it does. In which case, there are two questions within your question.
– cartant
3 hours ago
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
You can just use withLatestFrom
import { of, fromEvent, interval } from 'rxjs';
import { map, withLatestFrom } from 'rxjs/operators';
const input$ = fromEvent(document, 'keydown').pipe( map((event: KeyboardEvent) => event.keyCode));
const timer$ = interval(1000);
const source$ = timer$.pipe(withLatestFrom(input$));
source$.subscribe(x => console.log(x));
Try out this live demo at stackblitz -> https://stackblitz.com/edit/rxjs-bmx7hg
As soon as you focus the page and press some key, the stream will start and you will get an emitted value on every tick, no matter if you clicked a button since the last tick.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
You can just use withLatestFrom
import { of, fromEvent, interval } from 'rxjs';
import { map, withLatestFrom } from 'rxjs/operators';
const input$ = fromEvent(document, 'keydown').pipe( map((event: KeyboardEvent) => event.keyCode));
const timer$ = interval(1000);
const source$ = timer$.pipe(withLatestFrom(input$));
source$.subscribe(x => console.log(x));
Try out this live demo at stackblitz -> https://stackblitz.com/edit/rxjs-bmx7hg
As soon as you focus the page and press some key, the stream will start and you will get an emitted value on every tick, no matter if you clicked a button since the last tick.
add a comment |
up vote
0
down vote
You can just use withLatestFrom
import { of, fromEvent, interval } from 'rxjs';
import { map, withLatestFrom } from 'rxjs/operators';
const input$ = fromEvent(document, 'keydown').pipe( map((event: KeyboardEvent) => event.keyCode));
const timer$ = interval(1000);
const source$ = timer$.pipe(withLatestFrom(input$));
source$.subscribe(x => console.log(x));
Try out this live demo at stackblitz -> https://stackblitz.com/edit/rxjs-bmx7hg
As soon as you focus the page and press some key, the stream will start and you will get an emitted value on every tick, no matter if you clicked a button since the last tick.
add a comment |
up vote
0
down vote
up vote
0
down vote
You can just use withLatestFrom
import { of, fromEvent, interval } from 'rxjs';
import { map, withLatestFrom } from 'rxjs/operators';
const input$ = fromEvent(document, 'keydown').pipe( map((event: KeyboardEvent) => event.keyCode));
const timer$ = interval(1000);
const source$ = timer$.pipe(withLatestFrom(input$));
source$.subscribe(x => console.log(x));
Try out this live demo at stackblitz -> https://stackblitz.com/edit/rxjs-bmx7hg
As soon as you focus the page and press some key, the stream will start and you will get an emitted value on every tick, no matter if you clicked a button since the last tick.
You can just use withLatestFrom
import { of, fromEvent, interval } from 'rxjs';
import { map, withLatestFrom } from 'rxjs/operators';
const input$ = fromEvent(document, 'keydown').pipe( map((event: KeyboardEvent) => event.keyCode));
const timer$ = interval(1000);
const source$ = timer$.pipe(withLatestFrom(input$));
source$.subscribe(x => console.log(x));
Try out this live demo at stackblitz -> https://stackblitz.com/edit/rxjs-bmx7hg
As soon as you focus the page and press some key, the stream will start and you will get an emitted value on every tick, no matter if you clicked a button since the last tick.
edited 3 hours ago
answered 3 hours ago
Bene
28229
28229
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53400784%2fzipwithlatestform-wanted-operator-or-workaround%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Does the output at the beginning of your question actually represent your use case? I'm not at all sure that it does. In which case, there are two questions within your question.
– cartant
3 hours ago