How to indicate what a boolean parameter for an Angular filter represents - angularjs

If you look at something like this:
{{data | customFilter:true}} you won't know what that true stands for unless you look at the implementation of the filter.
Is there a more readable way of passing that argument, like customerFilter:{showLabel:true}?
Thanks.

Related

Xtend: evaluate expression directly from a string

Is there a possibilty in the Xtend language to evaluate an expression directly from a string, e.g. like Eval in Groovy. I want to do something like this in Xtend (the example is from Groovy):
import groovy.util.Eval
assert Eval.me('2*5') == 10
If there is no built-in way to do this, what would be the most similar alternative to achieve this (if any)?
P.S. Just to be clear: the expression is of course not just a simple math operation (like in the example); in particular, I would like to call my own Xtend function doing some transformation on a list.
I think there isn't anything like this in Xtend, so you should probably look for Java libraries that do this.
For example Java EL seems like a good standard way for evaluating strings. Since EL 3 there is the ELProcessor which doesn't require JSP anymore and it seems quite easy to use:
ELProcessor elp = new ELProcessor();
elp.defineBean("employee", new Employee("Charlie Brown"));
String name = elp.eval("employee.name");
Here is nice article about the latest features of EL, like lambda expression. The article also contains some examples about collections and how to call external methods.

ScalaTest: how to properly assert over Try values?

At the moment if I need to test that a value v of Try[T] type is Success(t) I do like:
v.isSuccess shouldBe true
I wonder if there are probably some better ways. For example, for Option[T] we can assert like:
t shouldBe defined
Probably there is something like this for Try[T] but I am not aware and searching the web does not help.
So far I came up with this solution:
Based on this section of the ScalaTest docs we declare such symbol value:
val successful = 'success and then assert like this:
CampaignRowsPage.reserveInventory shouldBe successful
Looks good to me.

Is the Angular orderBy documentation wrong? Or am I confused?

I'm a bit confused after reading Angular's orderBy documentation:
In HTML Template Binding:
{{ orderBy_expression | orderBy : array : expression : reverse}}`
This shows orderBy being used with 3 additional parameters (reverse is listed as optional), but I cannot find any examples of it being used with more than 2, and when it is 2, it appears to be in the form {{ orderBy_expression | orderBy : expression : reverse}} (ommitting array)
array is defined as "The array to sort.", but what does that make orderBy_expression? Shouldn't that be the array the filter acts upon?
I was actually going to Improve this doc and modify this (what I assume is a documentation error), but it wasn't at all clear to me what exactly was generating the template binding example (the docs are generated with JavaDoc-like comments right in the .js)
So, hopefully this is a valid SO question:
Is the documentation in fact incorrect? Or am I somehow confused
Filters have 2 modes of use. Programmatically, as a function, in which case the first param IS the array to act upon, and inline with | where the array on the left hand side is the array to act upon. So while it may not be immediately clear that is what is going on, the docs are not incorrect. Not saying it shouldn't be cleaned up. It would certainly be nicer if they showed both modes and clearly explained it. But I still stand by it being "correct." And, as Mikke pointed out, the current style of explanation IS consistent through the docs.

Can i use or logic in ng-when

I would like to do something like this:
<ANY ng-switch-when="matchValue1 || matchValue2">...</ANY>
To simplify my expression, currently I do that same thing for matchValue1 and matchValue2.
According to angular web site "Be aware that the attribute values to match against cannot be expressions. They are interpreted as literal string values to match against. For example, ng-switch-when="someVal" will match against the string "someVal" not against the value of the expression $scope.someVal."
Using ng-show would be useful in your case.

How to use (find)where in backbone to get a specific field of an array

I use to use the where method from the Collections in backbone. But I don't see how to fetch this result:
MyCollection.Group[x].id
As you can guess, MyCollection is the collection, Group is an array, and id is the field I would like to match for a specific value, something like:
MyCollection.findWhere(Group[x].id: 34);
I have seen the "contains" function of underscore but it doesn't seems to work with associative arrays
Is there a way to do it or should we parse the collection manually using Javascript ?
Collection.where and Collection.findWhere are convenience functions for simple filters. In your case, you would use the more complex Collection.find (proxied to _.find)
find _.find(list, iterator, [context])
Looks through each value in the list, returning the first one that passes a truth test
(iterator). The function returns as soon as it finds an acceptable
element, and doesn't traverse the entire list.
And if I understand correctly your condition, it could look like
MyCollection.find(function(model) {
return _.findWhere(model.get('Group'), {id: 34});
})
you can choose to use jQuery .find() . see examples here: http://api.jquery.com/find/

Resources