File tree Expand file tree Collapse file tree 1 file changed +9
-18
lines changed
packages/rrweb/src/record Expand file tree Collapse file tree 1 file changed +9
-18
lines changed Original file line number Diff line number Diff line change @@ -5,19 +5,8 @@ import type MutationBuffer from './mutation';
55 */
66export default class ProcessedNodeManager {
77 private nodeMap : WeakMap < Node , Set < MutationBuffer > > = new WeakMap ( ) ;
8- // Whether to continue RAF loop.
9- private loop = true ;
108
11- constructor ( ) {
12- this . periodicallyClear ( ) ;
13- }
14-
15- private periodicallyClear ( ) {
16- requestAnimationFrame ( ( ) => {
17- this . clear ( ) ;
18- if ( this . loop ) this . periodicallyClear ( ) ;
19- } ) ;
20- }
9+ private active = false ;
2110
2211 public inOtherBuffer ( node : Node , thisBuffer : MutationBuffer ) {
2312 const buffers = this . nodeMap . get ( node ) ;
@@ -27,15 +16,17 @@ export default class ProcessedNodeManager {
2716 }
2817
2918 public add ( node : Node , buffer : MutationBuffer ) {
19+ if ( ! this . active ) {
20+ this . active = true ;
21+ requestAnimationFrame ( ( ) => {
22+ this . nodeMap = new WeakMap ( ) ;
23+ this . active = false ;
24+ } ) ;
25+ }
3026 this . nodeMap . set ( node , ( this . nodeMap . get ( node ) || new Set ( ) ) . add ( buffer ) ) ;
3127 }
3228
33- private clear ( ) {
34- this . nodeMap = new WeakMap ( ) ;
35- }
36-
3729 public destroy ( ) {
38- // Stop the RAF loop.
39- this . loop = false ;
30+ // cleanup no longer needed
4031 }
4132}
You can’t perform that action at this time.
0 commit comments