A couple of additions: reduce and ifNull

2 views
Skip to first unread message

Bryan Matthews

unread,
Jul 13, 2011, 1:12:07 PM7/13/11
to ExoSuite
Just wanted to let everyone know that I checked in a couple of minor additions to exoweb.

reduce

MDN documentation

Apply a function against an accumulator and each value of the array (from left-to-right) as to reduce it to a single value.

This is a fairly new function, so its not available in IE8 and earlier.  I added an fallback implementation to exoweb based on the example at the previous link.

Here's an example of what you might use it for:

>> arr
[0, 5, 3, 13.4]
>> arr.reduce(function(a, b) { return a + b; }, 0);
21.4

Or, more realistically, you probably have an entity list and need to map to property values first:

this.get_Items().map(function(item) {
        return item.get_Value();
    }).reduce(function(a, b) {
        return a + b;
    }, 0);

ifNull

I added an option to the lazy markup extension to display static text if the path evaluates to null or undefined.  This is something that you could accomplish with toggle or sys:if, so its mainly for convenience and readability.

<span>{~ Person.Name, ifNull=n/a }</span>
Reply all
Reply to author
Forward
0 new messages