mirror of
https://github.com/flynx/diff.js.git
synced 2025-10-29 02:50:10 +00:00
added docs for type handler methods...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
d8a88ae039
commit
e3c93d182e
64
README.md
64
README.md
@ -232,21 +232,85 @@ If types of the not equal object pair mismatch `'Basic'` is used and both are st
|
|||||||
Adding new *synthetic* type handler:
|
Adding new *synthetic* type handler:
|
||||||
```javascript
|
```javascript
|
||||||
ExtendedDiff.types.set('SomeType', {
|
ExtendedDiff.types.set('SomeType', {
|
||||||
|
// Type check priority (optional)...
|
||||||
|
//
|
||||||
|
// Types are checked in order of occurrence in .handlers unless
|
||||||
|
// type .priority is set to a non 0 value.
|
||||||
|
//
|
||||||
|
// Default priorities:
|
||||||
|
// Text: 100
|
||||||
|
// Needs to run checks before 'Basic' as its targets are
|
||||||
|
// long strings that 'Basic' also catches.
|
||||||
|
// Basic: 50
|
||||||
|
// Needs to be run before we do other object checks.
|
||||||
|
// Object: -100
|
||||||
|
// Needs to run after everything else as it will match any
|
||||||
|
// set of objects.
|
||||||
|
//
|
||||||
|
// General guide:
|
||||||
|
// >50 - to be checked before 'Basic'
|
||||||
|
// <50 and >0 - after Basic but before unprioritized types
|
||||||
|
// <=50 and <0 - after unprioritized types but before Object
|
||||||
|
// <=100 - to be checked after Object -- this is a bit
|
||||||
|
// pointless in JavaScript.
|
||||||
|
//
|
||||||
|
// NOTE: when this is set to 0, then type will be checked in
|
||||||
|
// order of occurrence...
|
||||||
priority: null,
|
priority: null,
|
||||||
|
|
||||||
|
// Check if obj is compatible (optional)...
|
||||||
|
//
|
||||||
|
// .check(obj[, options])
|
||||||
|
// -> bool
|
||||||
|
//
|
||||||
check: function(obj, options){
|
check: function(obj, options){
|
||||||
// ...
|
// ...
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Handle/populate the diff of A and B...
|
||||||
|
//
|
||||||
|
// Input diff format:
|
||||||
|
// {
|
||||||
|
// type: <type-name>,
|
||||||
|
// }
|
||||||
|
//
|
||||||
handle: function(obj, diff, A, B, options){
|
handle: function(obj, diff, A, B, options){
|
||||||
// ...
|
// ...
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Walk the diff...
|
||||||
|
//
|
||||||
|
// This will pass each change to func(..) and return its result...
|
||||||
|
//
|
||||||
|
// .walk(diff, func, path)
|
||||||
|
// -> res
|
||||||
|
//
|
||||||
|
// NOTE: by default this will not handle attributes (.attrs), so
|
||||||
|
// if one needs to handle them Object's .walk(..) should be
|
||||||
|
// explicitly called...
|
||||||
|
// Example:
|
||||||
|
// walk: function(diff, func, path){
|
||||||
|
// var res = []
|
||||||
|
//
|
||||||
|
// // handle specific diff stuff...
|
||||||
|
//
|
||||||
|
// return res
|
||||||
|
// // pass the .items handling to Object
|
||||||
|
// .concat(this.typeCall(Object, 'walk', diff, func, path))
|
||||||
|
// }
|
||||||
walk: function(diff, func, path){
|
walk: function(diff, func, path){
|
||||||
// ...
|
// ...
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Patch the object...
|
||||||
|
//
|
||||||
patch: function(target, key, change, root, options){
|
patch: function(target, key, change, root, options){
|
||||||
// ...
|
// ...
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
// Reverse the change in diff...
|
||||||
|
//
|
||||||
reverse: function(change){
|
reverse: function(change){
|
||||||
// ...
|
// ...
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user