How to use Object.deliverChangeRecords method in javascript

I understand how to use Object.observe()

and Object.getNotifier(obj).notify

or Object.getNotifier(obj).performChange

, but how to useObject.deliverChangeRecords()

+3


source to share


1 answer


The point of Object.deliverChangeRecords is to receive synchronous delivery to the function that listens for mutations.

http://www.danyow.net/object-deliverchangerecords/

Here's an example of how it works, showing 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>
      

Run codeHide result


+6


source







All Articles