Skip to content

Commit

Permalink
Merge pull request #27 from mkohlmyr/mo-character-data
Browse files Browse the repository at this point in the history
fix(nodejs-pal-builder) MutationObserver not handling changes to CharacterData.data
  • Loading branch information
EisenbergEffect authored May 16, 2018
2 parents f183c5d + 130666c commit 56396ff
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
27 changes: 27 additions & 0 deletions spec/mutation-observer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,33 @@ describe("MutationObserver", () => {
text.nodeValue = "B";
});

it("character data changes trigger mutation event", function (done) {
var pal = buildPal();
var dom = pal.dom;
var document = pal.global.window.document;
var text = document.createTextNode("A");

var observer = dom.createMutationObserver((changes) => {
try {
expect(changes.length).toBe(1);
expect(changes[0].oldValue).toBe("A");
}
catch (err) {
fail();
}
finally {
observer.disconnect();
done();
}
});

observer.observe(text, {
characterData: true
});

text.data = "B";
});

it("child-node changes trigger mutation event", function (done) {
var pal = buildPal();
var dom = pal.dom;
Expand Down
4 changes: 4 additions & 0 deletions src/nodejs-pal-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ function patchNotifyChange(window: Window) {
intersectSetter(node_proto, "nodeValue", notify);
intersectSetter(node_proto, "textContent", notify);

let char_proto = (<any>window)._core.CharacterData.prototype;

intersectSetter(char_proto, "data", notify);

let element_proto = (<any>window)._core.Element.prototype;

intersectMethod(element_proto, "setAttribute", notify);
Expand Down

0 comments on commit 56396ff

Please sign in to comment.