mirror of
https://github.com/flynx/diff.js.git
synced 2025-10-29 11:00:12 +00:00
tweaking, notes and cleanup...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
5e32c539ba
commit
2ec8480604
33
diff2.js
33
diff2.js
@ -67,11 +67,12 @@ module.CONTENT =
|
|||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// .handle(obj, res, next, stop)
|
// .handle(obj, res, next(..), stop(..), options)
|
||||||
// -> [path, res]
|
// -> [path, res]
|
||||||
// -> undefined
|
// -> undefined
|
||||||
//
|
//
|
||||||
// res ::= [path] | [path, value]
|
// res ::= [path]
|
||||||
|
// | [path, value]
|
||||||
//
|
//
|
||||||
// next([path, value], ..)
|
// next([path, value], ..)
|
||||||
// -> true
|
// -> true
|
||||||
@ -81,14 +82,10 @@ module.CONTENT =
|
|||||||
//
|
//
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// NOTE: this is more of a grammar than a set of object handlers, nother
|
// NOTE: this is more of a grammar than a set of object handlers, another
|
||||||
// way to think of this is as a set of handlrs of aspects of objects
|
// way to think of this is as a set of handlers of aspects of objects
|
||||||
// and not full objects...
|
// and not full objects...
|
||||||
// XXX not sure if this is how this is going to continue though as
|
|
||||||
// we'll need to organize constructors preferably within this
|
|
||||||
// structure and keep it extensible...
|
|
||||||
//
|
//
|
||||||
// XXX need option threading...
|
|
||||||
// XXX need to deal with functions...
|
// XXX need to deal with functions...
|
||||||
// XXX add a tree mode -- containers as levels...
|
// XXX add a tree mode -- containers as levels...
|
||||||
// XXX need a way to index the path...
|
// XXX need a way to index the path...
|
||||||
@ -128,7 +125,7 @@ module.HANDLERS = {
|
|||||||
//
|
//
|
||||||
// XXX EXPERIMENTAL...
|
// XXX EXPERIMENTAL...
|
||||||
text: {
|
text: {
|
||||||
handle: function(obj, res, next, stop){
|
handle: function(obj, res, next, stop, options){
|
||||||
typeof(obj) == 'string'
|
typeof(obj) == 'string'
|
||||||
// XXX make this more optimal...
|
// XXX make this more optimal...
|
||||||
&& obj.includes('\n')
|
&& obj.includes('\n')
|
||||||
@ -268,6 +265,15 @@ module.HANDLERS = {
|
|||||||
var handle =
|
var handle =
|
||||||
module.handle =
|
module.handle =
|
||||||
function*(obj, path=[], options={}){
|
function*(obj, path=[], options={}){
|
||||||
|
// parse args...
|
||||||
|
options = typeof(path) == 'object' && !(path instanceof Array) ?
|
||||||
|
path
|
||||||
|
: options
|
||||||
|
path = path instanceof Array ?
|
||||||
|
path
|
||||||
|
: typeof(path) == 'string' ?
|
||||||
|
str2path(path)
|
||||||
|
: []
|
||||||
// handle object loops...
|
// handle object loops...
|
||||||
var seen = options.seen =
|
var seen = options.seen =
|
||||||
options.seen || new Map()
|
options.seen || new Map()
|
||||||
@ -289,11 +295,14 @@ function*(obj, path=[], options={}){
|
|||||||
// handle the object...
|
// handle the object...
|
||||||
var handlers = options.handlers || module.HANDLERS
|
var handlers = options.handlers || module.HANDLERS
|
||||||
var res = [path]
|
var res = [path]
|
||||||
yield* Object.values(handlers)
|
yield* Object.entries(handlers)
|
||||||
.iter()
|
.iter()
|
||||||
.filter(function(handler){
|
.filter(function([_, handler]){
|
||||||
return !!handler.handle })
|
return !!handler.handle })
|
||||||
.map(function*(handler){
|
.map(function*([name, handler]){
|
||||||
|
// skip...
|
||||||
|
if(!!options['no'+ name.capitalize()]){
|
||||||
|
return }
|
||||||
// expand aliases...
|
// expand aliases...
|
||||||
var h = handler
|
var h = handler
|
||||||
while(h && typeof(h.handle) == 'string'){
|
while(h && typeof(h.handle) == 'string'){
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user