cujojs / jiff

JSON Patch and diff based on rfc6902
Other
627 stars 41 forks source link

Add commutation #16

Closed briancavalier closed 10 years ago

briancavalier commented 10 years ago

This is not a complete implementation, so I'm labeling it as experimental in the README. It handles patches that either refer to elements in the same array, or where one refers to a descendent of an element in the same array as the other. IOW, the common ancestor must be an array.

Tree (object) commutation will come later, but we don't really need it for our current use cases.

Trying to commute patches that cannot be commuted will throw a TypeError. For example, trying to commute a patch that adds an array element, and a patch that removes that same element: you can't remove an item before you add it.