mirror of
https://github.com/flynx/diff.js.git
synced 2025-10-29 11:00:12 +00:00
tweaking...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
987c4c2c79
commit
255ff641fd
39
diff2.js
39
diff2.js
@ -113,20 +113,21 @@ function*(obj){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// XXX use STOP...
|
||||||
var getHandlers =
|
var getHandlers =
|
||||||
module.getHandlers =
|
module.getHandlers =
|
||||||
function(obj, handlers=module.HANDLERS){
|
function(obj, handlers=module.HANDLERS){
|
||||||
var stop = false
|
return [...Object.entries(handlers)
|
||||||
return Object.entries(handlers)
|
.iter()
|
||||||
.filter(function([k, v]){
|
.filter(function([k, v]){
|
||||||
return stop ?
|
if(v.final
|
||||||
false
|
&& v.match
|
||||||
// XXX this is a bit ugly...
|
&& v.match(obj)){
|
||||||
: (v.match
|
throw types.STOP(true) }
|
||||||
&& v.match(obj)
|
return v.match
|
||||||
&& (stop = v.final, true)) })
|
&& v.match(obj) })
|
||||||
.map(function([k, v]){
|
.map(function([k, v]){
|
||||||
return v }) }
|
return v })] }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -186,17 +187,17 @@ function*(obj, path=[], options={}){
|
|||||||
: subtree(handler.handle(obj, path, options)) }) }
|
: subtree(handler.handle(obj, path, options)) }) }
|
||||||
|
|
||||||
|
|
||||||
var _serializePath = function(p){
|
|
||||||
|
// XXX need a better way to serialize the path...
|
||||||
|
var serializePathElem = function(p){
|
||||||
return typeof(p) == 'object' ?
|
return typeof(p) == 'object' ?
|
||||||
JSON.stringify(p)
|
JSON.stringify(p)
|
||||||
: p }
|
: p }
|
||||||
var serializePath = function(p){
|
var serializePath = function(p){
|
||||||
return '/'+ p.map(_serializePath).join('/') }
|
return '/'+ p.map(serializePathElem).join('/') }
|
||||||
|
var serializePaths =
|
||||||
// XXX need a better way to serialize the path...
|
module.serializePaths =
|
||||||
var shandle =
|
types.generator.iter
|
||||||
module.shandle =
|
|
||||||
handle
|
|
||||||
.map(function([p, v]){
|
.map(function([p, v]){
|
||||||
return (
|
return (
|
||||||
// XXX revise...
|
// XXX revise...
|
||||||
@ -234,7 +235,11 @@ var o = {
|
|||||||
// loop...
|
// loop...
|
||||||
o.object.y = o.object
|
o.object.y = o.object
|
||||||
|
|
||||||
console.log([...shandle(o)])
|
|
||||||
|
|
||||||
|
console.log([
|
||||||
|
...handle(o)
|
||||||
|
.chain(serializePaths)])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user