@@ -1306,24 +1306,31 @@ var uPlot = (function () {
13061306
13071307 var syncs = { } ;
13081308
1309- function _sync ( opts ) {
1310- var clients = [ ] ;
1311-
1312- return {
1313- sub : function sub ( client ) {
1314- clients . push ( client ) ;
1315- } ,
1316- unsub : function unsub ( client ) {
1317- clients = clients . filter ( c => c != client ) ;
1318- } ,
1319- pub : function pub ( type , self , x , y , w , h , i ) {
1320- if ( clients . length > 1 ) {
1321- clients . forEach ( client => {
1322- client != self && client . pub ( type , self , x , y , w , h , i ) ;
1323- } ) ;
1309+ function _sync ( key , opts ) {
1310+ var s = syncs [ key ] ;
1311+
1312+ if ( ! s ) {
1313+ var clients = [ ] ;
1314+
1315+ s = {
1316+ key : key ,
1317+ sub : function sub ( client ) {
1318+ clients . push ( client ) ;
1319+ } ,
1320+ unsub : function unsub ( client ) {
1321+ clients = clients . filter ( c => c != client ) ;
1322+ } ,
1323+ pub : function pub ( type , self , x , y , w , h , i ) {
1324+ for ( var i$1 = 0 ; i$1 < clients . length ; i$1 ++ )
1325+ { clients [ i$1 ] != self && clients [ i$1 ] . pub ( type , self , x , y , w , h , i$1 ) ; }
13241326 }
1325- }
1326- } ;
1327+ } ;
1328+
1329+ if ( key != null )
1330+ { syncs [ key ] = s ; }
1331+ }
1332+
1333+ return s ;
13271334 }
13281335
13291336 function orient ( u , seriesIdx , cb ) {
@@ -4345,7 +4352,7 @@ var uPlot = (function () {
43454352
43464353 var syncKey = syncOpts . key ;
43474354
4348- var sync = ( syncKey != null ? ( syncs [ syncKey ] = syncs [ syncKey ] || _sync ( ) ) : _sync ( ) ) ;
4355+ var sync = _sync ( syncKey ) ;
43494356
43504357 sync . sub ( self ) ;
43514358
@@ -4409,6 +4416,10 @@ var uPlot = (function () {
44094416 uPlot . tzDate = tzDate ;
44104417 }
44114418
4419+ {
4420+ uPlot . sync = _sync ;
4421+ }
4422+
44124423 {
44134424 uPlot . addGap = addGap ;
44144425 uPlot . clipGaps = clipGaps ;
0 commit comments