Skip to content

Commit

Permalink
Simplify cursor code and more plus add support for IE11
Browse files Browse the repository at this point in the history
  • Loading branch information
erikolson186 committed Feb 26, 2017
1 parent bc62520 commit 9ec68da
Show file tree
Hide file tree
Showing 36 changed files with 2,317 additions and 2,414 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ doc: { count: 1, age: 28 }
```html
<script src="https://unpkg.com/zangodb@latest/dist/zangodb.min.js"></script>
```

For certain web browsers, such as Internet Explorer, the Babel polyfill is required and must be loaded before ZangoDB:

```html
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/6.23.0/polyfill.min.js"></script>
```

**ZangoDB** then can be accessed using the global variable `zango`.

To install **ZangoDB** for usage with [node](https://nodejs.org/):
Expand Down
38 changes: 4 additions & 34 deletions build/src/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,36 +39,6 @@ var Collection = function () {
value: function _isIndexed(path) {
return this._indexes.has(path) || path === '_id';
}
}, {
key: '_getIndexSize',
value: function _getIndexSize(path, cb) {
var _this = this;

var count = 0;

this._db._getConn(function (error, idb) {
if (error) {
return cb(error);
}

var trans = idb.transaction([_this._name], 'readonly');

trans.oncomplete = function () {
return cb(null, count);
};
trans.onerror = function (e) {
return cb(getIDBError(e));
};

var store = trans.objectStore(_this._name),
index = store.index(path),
req = index.count();

req.onsuccess = function (e) {
return count = e.target.result;
};
});
}

/**
* Open a cursor and optionally filter documents and apply a projection.
Expand Down Expand Up @@ -171,7 +141,7 @@ var Collection = function () {
}, {
key: 'insert',
value: function insert(docs, cb) {
var _this2 = this;
var _this = this;

if (!Array.isArray(docs)) {
docs = [docs];
Expand All @@ -183,7 +153,7 @@ var Collection = function () {
var trans = void 0;

try {
trans = idb.transaction([_this2._name], 'readwrite');
trans = idb.transaction([_this._name], 'readwrite');
} catch (error) {
return deferred.reject(error);
}
Expand All @@ -195,15 +165,15 @@ var Collection = function () {
return deferred.reject(getIDBError(e));
};

var store = trans.objectStore(_this2._name);
var store = trans.objectStore(_this._name);

var i = 0;

var iterate = function iterate() {
var doc = docs[i];

try {
_this2._validate(doc);
_this._validate(doc);
} catch (error) {
return deferred.reject(error);
}
Expand Down
Loading

0 comments on commit 9ec68da

Please sign in to comment.