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

Commit

Permalink
fix: add support for WebKitMutationObserver
Browse files Browse the repository at this point in the history
  • Loading branch information
btford committed Apr 18, 2014
1 parent a52f19d commit d1a2c8e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
35 changes: 35 additions & 0 deletions test/zone.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,41 @@ describe('Zone.patch', function () {
});
});

describe('WebKitMutationObserver', function () {
it('should work', function () {
if (!window.WebKitMutationObserver) {
console.log('WARNING: skipping WebKitMutationObserver test (missing this API)');
return;
}

var flag = false,
elt = document.createElement('div'),
hasParent;

runs(function () {
var ob = new WebKitMutationObserver(function () {
hasParent = !!window.zone.parent;
flag = true;
});

ob.observe(elt, {
childList: true
});

elt.innerHTML = '<p>hey</p>';
});

waitsFor(function() {
return flag;
}, 'mutation observer to fire', 100);

runs(function() {
expect(hasParent).toBe(true);
});

});
});

describe('XMLHttpRequest', function () {

it('should work with onreadystatechange', function () {
Expand Down
7 changes: 3 additions & 4 deletions zone.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,8 @@ Zone.patch = function patch () {
'catch'
]);
}
if (window.MutationObserver) {
Zone.patchClass('MutationObserver');
}
Zone.patchClass('MutationObserver');
Zone.patchClass('WebKitMutationObserver');
};

//
Expand Down Expand Up @@ -333,7 +332,7 @@ Zone.patchClass = function (className) {
}
};

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

var prop;
for (prop in instance) {
Expand Down

0 comments on commit d1a2c8e

Please sign in to comment.