- 
        Couldn't load subscription status. 
- Fork 223
Closed
Description
If we remove items from an array using Array.prototype.splice() the order of patches generated by jsonpatch.generate() differs, depending on whether jsonpatch.observe() uses native Object.observe or a shim.
Lets take a sample test case:
it('should generate the same patch using Object.observe and shim after removing items from array', 
function() {
      var arr1 = [
        ["Albert", "Einstein"],
        ["Erwin", "Shrodinger"]
      ];
      var arr2 = arr1.slice();
      var observer1 = jsonpatch.observe(arr1);
      arr1.splice(0, 2);
      var objectObservePatches = jsonpatch.generate(observer1);
      var _observe = Object.observe;
      Object.observe = undefined;
      var observer2 = jsonpatch.observe(arr2);
      arr2.splice(0, 2);
      var shimPatches = jsonpatch.generate(observer2);
      expect(objectObservePatches).toEqual(shimPatches); //fails
      Object.observe = _observe;
});
 
the value stored in objectObservePatches is
[ { op : 'remove', path : '/1' }, { op : 'remove', path : '/0' }, 
{ op : 'replace', path : '/length', value : 0 } ]
whereas shimPatches contains array:
[ { op : 'remove', path : '/0' }, { op : 'remove', path : '/1' } ]
Ignoring patches related to length property (#14) patches generated by Object.observe() version indicate that we first removed item with index 1 and then 0 whereas shim version suggests something opposite.