File tree Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,20 @@ import { scaleLinear } from 'd3-scale';
6
6
7
7
import Pythagoras from './Pythagoras' ;
8
8
9
+
10
+ // borrowed from Vue fork https://github.com/yyx990803/vue-fractal/blob/master/src/App.vue
11
+ function throttleWithRAF ( fn ) {
12
+ let running = false
13
+ return function ( ) {
14
+ if ( running ) return
15
+ running = true
16
+ window . requestAnimationFrame ( ( ) => {
17
+ fn . apply ( this , arguments )
18
+ running = false
19
+ } )
20
+ }
21
+ }
22
+
9
23
class App extends Component {
10
24
svg = {
11
25
width : 1280 ,
@@ -17,7 +31,7 @@ class App extends Component {
17
31
heightFactor : 0 ,
18
32
lean : 0
19
33
} ;
20
-
34
+ running = false ;
21
35
realMax = 11 ;
22
36
23
37
componentDidMount ( ) {
@@ -35,7 +49,13 @@ class App extends Component {
35
49
}
36
50
}
37
51
52
+ // Throttling approach borrowed from Vue fork
53
+ // https://github.com/yyx990803/vue-fractal/blob/master/src/App.vue
54
+ // rAF makes it slower than just throttling on React update
38
55
onMouseMove ( event ) {
56
+ if ( this . running ) return ;
57
+ this . running = true ;
58
+
39
59
const [ x , y ] = d3mouse ( this . refs . svg ) ,
40
60
41
61
scaleFactor = scaleLinear ( ) . domain ( [ this . svg . height , 0 ] )
@@ -48,6 +68,7 @@ class App extends Component {
48
68
heightFactor : scaleFactor ( y ) ,
49
69
lean : scaleLean ( x )
50
70
} ) ;
71
+ this . running = false ;
51
72
}
52
73
53
74
render ( ) {
You can’t perform that action at this time.
0 commit comments