import * as d3 from 'd3' ; import xs from 'xstream' ; export default function transition < T > ( duration , start , end , interpolatorFactory = d3 . interpolate ) { let rafId ; return xs . create < T > ( { start ( out ) { const startTime = performance . now ( ) ; const inp = interpolatorFactory ( start , end ) ; function fn ( ) { const t = performance . now ( ) - startTime ; if ( t >= duration ) { out . next ( end ) ; out . complete ( ) ; return ; } out . next ( inp ( t / duration ) ) ; rafId = requestAnimationFrame ( fn ) ; } fn ( ) ; } , stop ( ) { cancelAnimationFrame ( rafId ) ; } , } ) ; }