Object.observe(native&shimmed) vs DOM event callbacks

by Tomek

HTML

<script src="http://cdn.jsdelivr.net/fast-json-patch/latest/json-patch-duplex.min.js"></script>
<input id="edit" value="edit me, then blur"/>
Watch the console output

JavaScript

var myObj = {value:"edit me, then blur"};
var observer = jsonpatch.observe(myObj, function(patches){
  console.log("observed change", patches);}
);
var input = document.getElementById("edit");
input.addEventListener("keyup", function(event){
  console.log("myObj.value changed to", input.value);
  myObj.value = input.value;
});
input.addEventListener("blur", function(event){
  console.log("input blured", input.value);
  console.log("call generate", jsonpatch.generate(observer));
});