3

I understand how to use Object.observe(), and Object.getNotifier(obj).notify or Object.getNotifier(obj).performChange, but how do I use Object.deliverChangeRecords()

Bergi
  • 513,640
  • 108
  • 821
  • 1,164
Edwin Reynoso
  • 1,413
  • 7
  • 18

1 Answers1

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
  • @Edwin - I've improved the code sample and made it interactive – Jeremy Danyow Apr 23 '15 at 01:56