material-motion-js icon indicating copy to clipboard operation
material-motion-js copied to clipboard

Stack overflow when the source is the inverse of a sink

Open appsforartists opened this issue 5 years ago • 0 comments

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.

appsforartists avatar Mar 08 '19 02:03 appsforartists