Filter down an observable store https://github.com/flams/observable-store.
A filtered observable-store will:
- Return a
count
of items that match the filter - Only
loop
over items that match the filter - Only trigger events on items that match the filter
npm install filter-observable-store
var Store = require("observable-store");
var Filter = require("filter-observable-store");
var store = new Store([5, 10, 15]);
// Create a new filter around an existing store
var filter = new Filter(store);
// Set a filter function
filter.setFilter(function (value) {
return value >= 10;
}, scope);
// Get filtered count:
filter.count(); // 2
// Loop over filtered items
filter.loop(function (value) {
// value... 10, 15...
});
// See if an item is in the filtered model
filter.has(5); // false
filter.has(10); // true
// Clear filter
filter.clearFilter();
- Add filtered has()
- first release
MIT