Skip to content

Commit 3e94273

Browse files
committed
feat: new method iterate
BREAKING CHANGE: the method `search` has been removed and replaced with `iterate` that can potentially do the same but is based on the localForage function `iterate` and is way more optimised. Fixes scotttrinh#42
1 parent 8680c68 commit 3e94273

File tree

6 files changed

+629
-743
lines changed

6 files changed

+629
-743
lines changed

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,18 @@ angular.module('yourModule', ['LocalForageModule'])
6060

6161
- `length()`: returns the number of items stored (async, promise)
6262

63-
- `search(filter)`: returns all the items for which filter returns true (filter is a function taking key,value as params) (async, promise)
63+
- `iterate(iteratorCallback)`: Iterate over all value/key pairs in datastore. (async, promise)
64+
65+
Iterate supports early exit by returning non `undefined` value inside `iteratorCallback` callback.
66+
Resulting value will be passed to the promise as the result of iteration.
67+
You can use this to make a search in your data:
6468
```js
65-
$localForage.search(function(key, value) {
66-
return "myKey" == key && "something" == value;
69+
$localForage.iterate(function(value, key) {
70+
if(angular.isInt(value) && value > 10) {
71+
return key;
72+
}
6773
}).then(function(data) {
68-
// do something
74+
// data is the key of the value > 10
6975
});
7076
```
7177

0 commit comments

Comments
 (0)