Reputation: 1531
I understand how to use Object.observe()
, and Object.getNotifier(obj).notify
or Object.getNotifier(obj).performChange
, but how do I use Object.deliverChangeRecords()
Upvotes: 3
Views: 283
Reputation: 26406
The point of Object.deliverChangeRecords is to get synchronous delivery to the function that is listening to the mutations.
http://www.danyow.net/object-deliverchangerecords/
Here's a running example that demonstrates the sequence of events with and without deliverChangeRecords
:
var output = document.getElementById('output');
function runTest(useDeliver) {
var obj = {};
output.textContent = '';
function handleChange(records) {
output.textContent += 'CHANGE DELIVERED\n';
}
Object.observe(obj, handleChange);
output.textContent += '1\n';
obj.a = 'b';
output.textContent += '2\n';
if (useDeliver) {
Object.deliverChangeRecords(handleChange);
}
output.textContent += '3\n';
}
<button onclick="runTest(true)">With deliverChangeRecords</button>
<button onclick="runTest(false)">Without deliverChangeRecords</button>
<pre id="output"></pre>
Upvotes: 6