Why is the minimum code not equivalent to the original?

When I started the MVC 4 project in Release mode, one page using SlickGrid did not display correctly (the grid is very, very high, and there are no grid cells).

However, I don’t think this is a SlickGrid problem, but rather how the middleware ( System.Web.Optimization built into MVC 4) minimized the code.

I grabbed the JavaScript mini code and started undoing minimization in one area at a time until the problem was fixed. I found that change (and forgive the scroll, I want to leave the mini version exactly as it is)

 function SlickFilter(n,t){var i=n.option,r=t.searchString;return n.pctSortKey.key<t.percentCompleteThreshold||r!=""&&i.indexOf(r)==-1&&i!="Unweighted Response"&&i!="Median"&&i!="Average"?!1:!0} 

to the original

 function SlickFilter(item, args) { if (item.pctSortKey.key < args.percentCompleteThreshold) { return false; } if (args.searchString != "" && item.option.indexOf(args.searchString) == -1 && item.option != "Unweighted Response" && item.option != "Median" && item.option != "Average") { return false; } return true; } 

solves the problem if all other elements of the mini file are not changed

The function is used as:

 dataView.setFilter(SlickFilter); 

to provide a callback function for SlickGrid to filter specific results.

How is it that the original and mini-functions are not equivalent?

UPDATE

SlickGrid "compiles" the filter function that I provide. This compilation step does not work with the mini version. The compiled abbreviated code is as follows:

 function anonymous(_items,_args) { var _retval = [], _idx = 0; var n, t = _args; _coreloop: for (var _i = 0, _il = _items.length; _i < _il; _i++) { n = _items[_i]; //debugger; var i = n.option, r = t.searchString; return n.pctSortKey.key < t.percentCompleteThreshold || r !="" && i.indexOf(r)==-1 && i != "Unweighted Response" && i != "Median" && i != "Average" ? !1 : !0 ; } return _retval; } 

Pay attention to several return statements.

With this additional understanding, I was able to identify the corresponding SlickGrid error:

https://github.com/mleibman/SlickGrid/issues/301

+7
source share
1 answer

The only difference that I see is that item.option and args.searchString are evaluated even if the first condition is true if they were not in the source code.

Did you try to enter the code to find out what values ​​and how they act on them?

Here is the unreleased minitip code to save someone else doing the same, or if you want to try it and get into it.

 function SlickFilter(n,t) { var i = n.option, r = t.searchString; return n.pctSortKey.key < t.percentCompleteThreshold || r !="" && i.indexOf(r)==-1 && i != "Unweighted Response" && i != "Median" && i != "Average" ? !1 : !0 } 

EDIT (by OP)

This led me to the right path, but it turned out that SlickGrid "compiles" the filter function. There is a known issue that the compiler sometimes fails. In fact, compilation is optional and not necessary in this case, since minifier already creates optimized code.

https://github.com/mleibman/SlickGrid/issues/301

+4
source

All Articles