bergie / VIE

Semantic Interaction Framework for JavaScript
http://viejs.org/
MIT License
303 stars 56 forks source link

Provide filter method for entities #111

Open neogermi opened 12 years ago

neogermi commented 12 years ago

Though a developer could use the underscore filter method. It might be worth giving the developer some convenience methods at hand to enable him/her to filter entities

directly within VIE.

I'm thinking of something like:

var persons = vie.entities.filter({type: "Person"});
var entitiesWithNames = vie.entities.filter({attributes: [{"schema:name" : "*"}]});
var personsWithNameParis = vie.entities.filter({attributes: [{"type: "Person", "schema:name" : "Paris*"}]});

The idea here is to provide simple implementations of often-used functionality. Not to provide a full scope of all possible filter queries. For that, the native filter method should be used (which is still possible, given the above syntax).

bergie commented 12 years ago

Sounds very useful. Have you seen the new Collection where method in Backbone? That would probably be the right place instead of filter

neogermi commented 12 years ago

No, haven't seen that before but I just gave it a try. My only issue with this is that it is actually a bit too simple. No regular expressions seem to work here. And filtering for types including their hierarchy would not be possible with that.

I will work on the above API during this week's hackathon in Copenhagen and we can discuss on this in Salzburg the week after.