-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.js
43 lines (36 loc) · 1.04 KB
/
log.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const MutationEncoder = require("./encoder");
const MutationDecoder = require("./decoder");
class Logger {
constructor() {
this._decoder = new MutationDecoder(document);
}
mutations(bytes) {
let decoder = this._decoder;
console.group("Mutations");
for(let mutation of decoder.decode(bytes)) {
console.log(mutation);
}
console.groupEnd();
}
}
exports.Logger = Logger;
exports.element = function(root, options) {
let encoder = new MutationEncoder(root, options);
let decoder = new MutationDecoder(root.ownerDocument);
function callback(records) {
console.group("Mutations");
let bytes = encoder.encode(records);
for(let mutation of decoder.decode(bytes)) {
console.log(mutation);
}
console.groupEnd();
}
let mo = new MutationObserver(callback);
mo.observe(root, { subtree: true, characterData: true, childList: true, attributes: true });
return mo;
};
exports.instructions = function(bytes) {
console.warn("log.instructions is deprecated. Use log.Logger instead.");
let log = new Logger();
log.mutations(bytes);
};