material-motion-js
material-motion-js copied to clipboard
Stack overflow when the source is the inverse of a sink
This seems like it should work:
subscribe({
source: when(
pointerEvents.up$.rewriteTo({
value$: thresholdCrossed$,
onlyEmitWithUpstream: true,
})
).rewriteTo({
value$: dissolveSpring.destination$.inverted(),
onlyEmitWithUpstream: true,
}),
sink: dissolveSpring.destination$,
});
to toggle the destination of a spring when a threshold is crossed. dissolveSpring.destination$
is cyclic, but onlyEmitWithUpstream
should break the cycle. Nevertheless, it fails with a stack overflow.
Waiting a frame succeeds:
when(
pointerEvents.up$.rewriteTo({
value$: thresholdCrossed$,
onlyEmitWithUpstream: true,
})
).rewriteTo<number>({
value$: dissolveSpring.destination$.inverted(),
onlyEmitWithUpstream: true,
}).subscribe(
value => requestAnimationFrame(
() => dissolveSpring.destination = value
)
)
I'm guessing there's a bug in _reactiveMap
.