Skip to content

Commit

Permalink
Workaround to fix promises in IE11.
Browse files Browse the repository at this point in the history
Polymer polyfill has an incomplete implementation of Promises
webcomponents/webcomponentsjs#800
  • Loading branch information
manolo committed Aug 19, 2017
1 parent 1f62e5e commit d63e034
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions vaadin-pouchdb.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@

<script>
if (Promise && !Promise.all) {
// In IE11 we force couchdb to load its own implementation of promises
// since webcomponents-lite polyfill lacks the `.all` method.
// See: https://github.com/webcomponents/webcomponentsjs/issues/800
window.__Promise = Promise;
Promise = undefined;
}
</script>
<script src="../pouchdb/dist/pouchdb.js"></script>
<script>
if (window.__Promise) {
// We need to restore back old implementation of Promises.
// Pouchdb uses it's own internal PouchPromise reference.
Promise = window.__Promise;
window.__Promise = undefined;
}
</script>

<link rel="import" href="../polymer/polymer.html">

Expand Down Expand Up @@ -60,7 +76,7 @@
},
queryString: {
type: String,
value: ""
value: ''
}
},

Expand Down Expand Up @@ -106,7 +122,7 @@
this.close();
this.data = [];
if (this.dbname) {
console.log("PouchDB local connection to: " + this.dbname);
console.log('Vaadin-PouchDB connected locally to: ' + this.dbname);
this._db = new PouchDB(this.dbname);
this.async(function() {
this.fire('pouchdb-connect', this.dbname);
Expand Down Expand Up @@ -225,7 +241,7 @@
* @param {Function} func
*/
changes: function(func, conf) {
console.log("PouchDB listening to changes in: " + this.dbname);
console.log('Vaadin-PouchDB listening to changes in: ' + this.dbname);
this._changesHandler = this._db.changes(conf || {
since: 'now',
live: true,
Expand Down Expand Up @@ -284,7 +300,7 @@
query = this.queryString || query || this._indexes && this._indexes[0];

return this._debounce('query', () => {
console.log("Running Query");
console.log('Vaadin-PouchDB running the Query ' + (query ? query : 'allDocs'));
return (query ? this._db.query(query, conf) : this._db.allDocs(conf))
.then(function(req) {
if (req.rows) {
Expand All @@ -294,7 +310,7 @@
} else {
this.data = []
}
console.log('Query returned: ' + this.data.length + ' rows');
console.log('Vaadin-PouchDB query returned ' + this.data.length + ' rows.');
}.bind(this))
.then(this._statusdone.bind(this));
}, 250);
Expand All @@ -303,7 +319,7 @@
createIndex: function(prop) {
var views = {};
views[prop] = {
map: "function(doc){if(doc." + prop + ") emit(doc." + prop + ")}"
map: 'function(doc){if(doc.' + prop + ') emit(doc.' + prop + ')}'
}
var idx = {
_id: '_design/' + prop,
Expand All @@ -324,15 +340,15 @@
* @param {Function} err
*/
sync: function(fnc, err, conf) {
console.log("PouchDB syncing local: " + this.dbname + " to: " + this.remote);
console.log('Vaadin-PouchDB syncing local: ' + this.dbname + ' to: ' + this.remote);
if (!this._db || !this.remote || this._synchandler) return this._synchandler;
var opts = conf || {
timeout: 0
};
if (this.liveSync) {
opts.live = opts.retry = true;
}
console.log("PouchDB syncing local: " + this.dbname + " to: " + this.remote + " " + opts);
console.log('Vaadin-PouchDB syncing local: ' + this.dbname + ' to: ' + this.remote + ' ' + opts);
// TODO: normally the sync is in paused status, seems that active is
// only for the very short time some data is being transferred.
var h = this._db.sync(this.remote, opts);
Expand Down

0 comments on commit d63e034

Please sign in to comment.