Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit d1a2c8e

Browse files
committed
fix: add support for WebKitMutationObserver
1 parent a52f19d commit d1a2c8e

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

Diff for: test/zone.spec.js

+35
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,41 @@ describe('Zone.patch', function () {
359359
});
360360
});
361361

362+
describe('WebKitMutationObserver', function () {
363+
it('should work', function () {
364+
if (!window.WebKitMutationObserver) {
365+
console.log('WARNING: skipping WebKitMutationObserver test (missing this API)');
366+
return;
367+
}
368+
369+
var flag = false,
370+
elt = document.createElement('div'),
371+
hasParent;
372+
373+
runs(function () {
374+
var ob = new WebKitMutationObserver(function () {
375+
hasParent = !!window.zone.parent;
376+
flag = true;
377+
});
378+
379+
ob.observe(elt, {
380+
childList: true
381+
});
382+
383+
elt.innerHTML = '<p>hey</p>';
384+
});
385+
386+
waitsFor(function() {
387+
return flag;
388+
}, 'mutation observer to fire', 100);
389+
390+
runs(function() {
391+
expect(hasParent).toBe(true);
392+
});
393+
394+
});
395+
});
396+
362397
describe('XMLHttpRequest', function () {
363398

364399
it('should work with onreadystatechange', function () {

Diff for: zone.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,8 @@ Zone.patch = function patch () {
267267
'catch'
268268
]);
269269
}
270-
if (window.MutationObserver) {
271-
Zone.patchClass('MutationObserver');
272-
}
270+
Zone.patchClass('MutationObserver');
271+
Zone.patchClass('WebKitMutationObserver');
273272
};
274273

275274
//
@@ -333,7 +332,7 @@ Zone.patchClass = function (className) {
333332
}
334333
};
335334

336-
var instance = new OriginalClass(className === 'MutationObserver' ? function () {} : undefined);
335+
var instance = new OriginalClass(className.substr(-16) === 'MutationObserver' ? function () {} : undefined);
337336

338337
var prop;
339338
for (prop in instance) {

0 commit comments

Comments
 (0)