walls const$ = combineLatest(
range(0, constants.wallsCnt),
of(constants.canvasWidthPx),
of(constants.canvasHeightPx),
of(constants.wallSizePx),
)
.pipe(
map(([range, canvasWidthPx, canvasHeightPx, wallSizePx]) => {
return {
x: Math.floor(Math.random() * Math.floor(canvasWidthPx - wallSizePx)),
y: Math.floor(Math.random() * Math.floor(canvasHeightPx - wallSizePx)),
strength: Math.floor(Math.random() * Math.floor(constants.wallStrengthMax)) + 1,
}
}),
toArray(),
tap(v => {
console.log(v)
}),
).subscribe()
constants.wallsCnt = 3
walls const$ = range(0, constants.wallsCnt)
.pipe(
map(_ => {
return {
x: Math.floor(Math.random() * Math.floor(constants.canvasWidthPx - constants.wallSizePx)),
y: Math.floor(Math.random() * Math.floor(constants.canvasHeightPx - constants.wallSizePx)),
strength: Math.floor(Math.random() * Math.floor(constants.wallStrengthMax)) + 1,
}
}),
toArray(),
)
Find more questions by tags Reactive ExtensionsTypeScriptJavaScript
https://github.com/staltz/rxmarbles/blob/master/pa... - Emmie commented on April 19th 20 at 12:37
https://rxjs.dev/api/index/function/combineLatest
in combineLatest the order of threads is not important - Elody_Willms commented on April 19th 20 at 12:40
An Observable of projected values from the most recent values from each Observable input, or an array of the most recent values from each input Observable.
of range and give their values synchronously, i.e. it should work simultaneously, but simultaneity in js is not, so the order is important.
You when it came to the subscription of, range has worked.
Maybe it should be considered a bug in the rx and it's time to start issue.
There's even a clear indication of sheduler does not affect the result. - rashawn.Ve commented on April 19th 20 at 12:43