Closed hendrikcech closed 10 years ago
@hendrikcech you can initialize (or reset) a store with an array:
var store = new Store(['foo']);
store.get(0);
// => foo
you can loop through the store as following:
store.loop(function(idx, value){
// do something
});
store supports all the things in common between objects and arrays. By default you can't map or filter a store but I'm doing right now a plugin to extend a store with array-like features. Here's an example:
// create plugin that adds map to a store
store.use(function(ctx) {
ctx.map = function(fn) {
ctx.loop(function(idx, value) {
ctx.set(idx, fn(value));
});
};
});
Thanks! You may want to add the loop function to the README.
@hendrikcech yes I will. Do you like the project? Do you think some things are missing?
I may be missing the obvious, but how do I get all the data stored in a datastore object as an array? I would like to iterate over the items with forEach, map and so on.