Skip to content

Commit

Permalink
add xui.deepEqauls
Browse files Browse the repository at this point in the history
  • Loading branch information
linb committed Nov 16, 2020
1 parent 1ae10f4 commit da74c43
Show file tree
Hide file tree
Showing 6 changed files with 325 additions and 263 deletions.
504 changes: 253 additions & 251 deletions API/App/js/xui-raw.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion runtime/xui/js/xui-all.js

Large diffs are not rendered by default.

40 changes: 35 additions & 5 deletions runtime/xui/js/xui-debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,32 @@ new function(){
}else return hash;
}else return hash;
},
deepEquals:function(x, y, deep, ignore, _curLayer){
if(!xui.isSet(deep)) deep=100;
if(!xui.isSet(_curLayer))_curLayer = 1;

if (x === y) return true;
if (!(x instanceof Object) || !(y instanceof Object)) return false;
if (x.constructor !== y.constructor) return false;
for (let p in x) {
if (ignore && ignore(p)) continue;
if (!x.hasOwnProperty(p)) continue;
if (!y.hasOwnProperty(p)) return false;
if (x[p] === y[p]) continue;
if (typeof x[p] !== "object") return false;
if (xui.isHash(x[p]) && xui.isHash(y[p]) && xui.isEmpty(x[p])&& xui.isEmpty(y[p])) continue;
if (xui.isArr(x[p]) && xui.isArr(y[p]) && x[p].length === 0 && y[p].length === 0) continue;
if (_curLayer >= deep) {
if (x[p] !== y[p]) return false;
continue;
} else if (!xui.deepEquals(x[p], y[p], deep, ignore, _curLayer + 1))
return false;
}
for (let p in y) {
if (y.hasOwnProperty(p) && !x.hasOwnProperty(p)) return false;
}
return true;
},
/*filter hash/array
filter: filter function(will delete "return false")
*/
Expand Down Expand Up @@ -54343,7 +54369,10 @@ xui.Class("xui.UI.TreeGrid",["xui.UI","xui.absValue"],{
});
if(profile.beforePopShow)
editor.beforePopShow(function(editorprf, popCtl, items){
return profile.boxing().beforePopShow(profile, editorprf.$cell, editorprf, popCtl, items, editorprf.$cell._row, editorprf.$cell._col);
var rst;
if(editorEvents && editorEvents.beforePopShow)rst = editorEvents.beforePopShow(editorprf, popCtl, items);
rst = profile.boxing().beforePopShow(profile, editorprf.$cell, editorprf, popCtl, items, editorprf.$cell._row, editorprf.$cell._col);
return rst;
});
if(profile.afterPopShow)
editor.afterPopShow(function(editorprf, popCtl){
Expand Down Expand Up @@ -54706,12 +54735,13 @@ xui.Class("xui.UI.TreeGrid",["xui.UI","xui.absValue"],{
},dfun=function(){
// if(editor) xui.tryF(editor.undo,[],editor);
};
editor.onFocus(bfun).beforePopShow(function(editorPrf, popCtl,items){
editor.onFocus(bfun).beforePopShow(function(editorprf, popCtl,items){
bfun();
editor.onBlur(null);
// for compitable
if(profile.beforePopShow)
return profile.boxing().beforePopShow(profile, editorPrf.$cell, editorPrf, popCtl, items, editorPrf.$cell._row, editorPrf.$cell_col);
var rst;
if(editorEvents && editorEvents.beforePopShow)rst = editorEvents.beforePopShow(editorprf, popCtl, items);
if(profile.beforePopShow)rst = profile.boxing().beforePopShow(profile, editorprf.$cell, editorprf, popCtl, items, editorprf.$cell._row, editorprf.$cell_col);
return rst;
}).afterPopHide(function(){
cfun();
editor.onBlur(dfun);
Expand Down
2 changes: 1 addition & 1 deletion runtime/xui/js/xui.js

Large diffs are not rendered by default.

14 changes: 9 additions & 5 deletions xui/js/UI/TreeGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -6889,7 +6889,10 @@ xui.Class("xui.UI.TreeGrid",["xui.UI","xui.absValue"],{
});
if(profile.beforePopShow)
editor.beforePopShow(function(editorprf, popCtl, items){
return profile.boxing().beforePopShow(profile, editorprf.$cell, editorprf, popCtl, items, editorprf.$cell._row, editorprf.$cell._col);
var rst;
if(editorEvents && editorEvents.beforePopShow)rst = editorEvents.beforePopShow(editorprf, popCtl, items);
rst = profile.boxing().beforePopShow(profile, editorprf.$cell, editorprf, popCtl, items, editorprf.$cell._row, editorprf.$cell._col);
return rst;
});
if(profile.afterPopShow)
editor.afterPopShow(function(editorprf, popCtl){
Expand Down Expand Up @@ -7252,12 +7255,13 @@ xui.Class("xui.UI.TreeGrid",["xui.UI","xui.absValue"],{
},dfun=function(){
// if(editor) xui.tryF(editor.undo,[],editor);
};
editor.onFocus(bfun).beforePopShow(function(editorPrf, popCtl,items){
editor.onFocus(bfun).beforePopShow(function(editorprf, popCtl,items){
bfun();
editor.onBlur(null);
// for compitable
if(profile.beforePopShow)
return profile.boxing().beforePopShow(profile, editorPrf.$cell, editorPrf, popCtl, items, editorPrf.$cell._row, editorPrf.$cell_col);
var rst;
if(editorEvents && editorEvents.beforePopShow)rst = editorEvents.beforePopShow(editorprf, popCtl, items);
if(profile.beforePopShow)rst = profile.boxing().beforePopShow(profile, editorprf.$cell, editorprf, popCtl, items, editorprf.$cell._row, editorprf.$cell_col);
return rst;
}).afterPopHide(function(){
cfun();
editor.onBlur(dfun);
Expand Down
26 changes: 26 additions & 0 deletions xui/js/xui.js
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,32 @@ new function(){
}else return hash;
}else return hash;
},
deepEquals:function(x, y, deep, ignore, _curLayer){
if(!xui.isSet(deep)) deep=100;
if(!xui.isSet(_curLayer))_curLayer = 1;

if (x === y) return true;
if (!(x instanceof Object) || !(y instanceof Object)) return false;
if (x.constructor !== y.constructor) return false;
for (let p in x) {
if (ignore && ignore(p)) continue;
if (!x.hasOwnProperty(p)) continue;
if (!y.hasOwnProperty(p)) return false;
if (x[p] === y[p]) continue;
if (typeof x[p] !== "object") return false;
if (xui.isHash(x[p]) && xui.isHash(y[p]) && xui.isEmpty(x[p])&& xui.isEmpty(y[p])) continue;
if (xui.isArr(x[p]) && xui.isArr(y[p]) && x[p].length === 0 && y[p].length === 0) continue;
if (_curLayer >= deep) {
if (x[p] !== y[p]) return false;
continue;
} else if (!xui.deepEquals(x[p], y[p], deep, ignore, _curLayer + 1))
return false;
}
for (let p in y) {
if (y.hasOwnProperty(p) && !x.hasOwnProperty(p)) return false;
}
return true;
},
/*filter hash/array
filter: filter function(will delete "return false")
*/
Expand Down

0 comments on commit da74c43

Please sign in to comment.