@@ -57,8 +57,8 @@ Zone.prototype = {
57
57
return new Zone ( this , locals ) ;
58
58
} ,
59
59
60
- bind : function ( fn ) {
61
- this . enqueueTask ( fn ) ;
60
+ bind : function ( fn , skipEnqueue ) {
61
+ skipEnqueue || this . enqueueTask ( fn ) ;
62
62
var zone = this . fork ( ) ;
63
63
return function zoneBoundFn ( ) {
64
64
return zone . run ( fn , this , arguments ) ;
@@ -364,8 +364,8 @@ Zone.patch = function patch () {
364
364
'catch'
365
365
] ) ;
366
366
}
367
- Zone . patchClass ( 'MutationObserver' ) ;
368
- Zone . patchClass ( 'WebKitMutationObserver' ) ;
367
+ Zone . patchMutationObserverClass ( 'MutationObserver' ) ;
368
+ Zone . patchMutationObserverClass ( 'WebKitMutationObserver' ) ;
369
369
} ;
370
370
371
371
//
@@ -454,6 +454,62 @@ Zone.patchClass = function (className) {
454
454
} ;
455
455
} ;
456
456
457
+ // wrap some native API on `window`
458
+ Zone . patchMutationObserverClass = function ( className ) {
459
+ var OriginalClass = window [ className ] ;
460
+ if ( ! OriginalClass ) {
461
+ return ;
462
+ }
463
+ window [ className ] = function ( fn ) {
464
+ this . _o = new OriginalClass ( zone . bind ( fn , true ) ) ;
465
+ } ;
466
+
467
+ var instance = new OriginalClass ( function ( ) { } ) ;
468
+
469
+ window [ className ] . prototype . disconnect = function ( ) {
470
+ var result = this . _o . disconnect . apply ( this . _o , arguments ) ;
471
+ this . _active && zone . dequeueTask ( ) ;
472
+ this . _active = false ;
473
+ return result ;
474
+ } ;
475
+
476
+ window [ className ] . prototype . observe = function ( ) {
477
+ if ( ! this . _active ) {
478
+ zone . enqueueTask ( ) ;
479
+ }
480
+ dump ( this . _active )
481
+ this . _active = true ;
482
+ return this . _o . observe . apply ( this . _o , arguments ) ;
483
+ } ;
484
+
485
+ var prop ;
486
+ for ( prop in instance ) {
487
+ ( function ( prop ) {
488
+ if ( typeof window [ className ] . prototype !== undefined ) {
489
+ return ;
490
+ }
491
+ if ( typeof instance [ prop ] === 'function' ) {
492
+ window [ className ] . prototype [ prop ] = function ( ) {
493
+ return this . _o [ prop ] . apply ( this . _o , arguments ) ;
494
+ } ;
495
+ } else {
496
+ Object . defineProperty ( window [ className ] . prototype , prop , {
497
+ set : function ( fn ) {
498
+ if ( typeof fn === 'function' ) {
499
+ this . _o [ prop ] = zone . bind ( fn ) ;
500
+ } else {
501
+ this . _o [ prop ] = fn ;
502
+ }
503
+ } ,
504
+ get : function ( ) {
505
+ return this . _o [ prop ] ;
506
+ }
507
+ } ) ;
508
+ }
509
+ } ( prop ) ) ;
510
+ }
511
+ } ;
512
+
457
513
Zone . eventNames = 'copy cut paste abort blur focus canplay canplaythrough change click contextmenu dblclick drag dragend dragenter dragleave dragover dragstart drop durationchange emptied ended input invalid keydown keypress keyup load loadeddata loadedmetadata loadstart mousedown mouseenter mouseleave mousemove mouseout mouseover mouseup pause play playing progress ratechange reset scroll seeked seeking select show stalled submit suspend timeupdate volumechange waiting mozfullscreenchange mozfullscreenerror mozpointerlockchange mozpointerlockerror error' . split ( ' ' ) ;
458
514
Zone . onEventNames = Zone . eventNames . map ( function ( property ) {
459
515
return 'on' + property ;
0 commit comments