I understand how to use Object.observe()
, and Object.getNotifier(obj).notify
or Object.getNotifier(obj).performChange
, but how do I use Object.deliverChangeRecords()
Asked
Active
Viewed 269 times
3
Bergi
- 513,640
- 108
- 821
- 1,164
Edwin Reynoso
- 1,413
- 7
- 18
-
see this post :https://github.com/jdarling/Object.observe/issues/13 – Suchit kumar Dec 15 '14 at 04:27
-
I'm still confused on how the function works? I don't understand what it does? – Edwin Reynoso Dec 15 '14 at 04:36
1 Answers
6
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>
Jeremy Danyow
- 25,594
- 11
- 82
- 125
-
The link helped by taking me to the jsbin example, but you're example doesn't really help. I figured it out from the jsbin example. But before I mark it as correct. I would suggest changing your answer to something like the jsbin example for others who come accross this question: http://jsbin.com/qazipicipume/1/edit?js,console – Edwin Reynoso Apr 23 '15 at 00:52
-