1 |
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("vuepouch",[],t):"object"==typeof exports?exports.vuepouch=t():e.vuepouch=t()}(this,function(){return function(e){function t(o){if(n[o])return n[o].exports;var c=n[o]={i:o,l:!1,exports:{}};return e[o].call(c.exports,c,c.exports,t),c.l=!0,c.exports}var n={};return t.m=e,t.c=n,t.d=function(e,n,o){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:o})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=0)}([function(e,t,n){"use strict";function o(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)}function c(e,t,n){n.allDocs({include_docs:!0,descending:!0}).then(function(n){var c={};n.rows.forEach(function(e){c[e.id]=e.doc});var u=[].concat(o(new Set(Object.keys(c).map(function(e){return c[e].doctype}))));e.$options.pouchdb.uniques=u;Object.keys(c).forEach(function(n){u.forEach(function(o){c[n].doctype===o&&(e[t][o]||Vue.set(e[t],o,Object.create(null)),Vue.set(e[t][o],n,c[n]))})})})}function u(e,t,n,o){n.sync(o,{live:!0,retry:!0,include_docs:!0}).on("change",function(n){h(e,t,n)})}function r(e,t){t._id=(new Date).toISOString(),t.doctype=e;var n=this.localDB,o=this.vm,c=this.key;o[c][e]||Vue.set(o[c],[e],Object.create(null)),n.put(t).then(function(n){t.rev=n.rev,Vue.set(o[c][e],[t._id],t)})}function i(e,t){}function f(e){var t=this.localDB;this.key,this.vm;return t.put(e)}function a(e){var t=this.localDB;this.key,this.vm;return t.remove(e)}var s=function(e){var t=e.$options.pouchdb;if(t){d(e);for(var n in t)p(e,n,t[n]),l(e,n,t[n])}},d=function(e){e.$pouchdbRefs||(e.$pouchdbRefs=Object.create(null))},l=function(e,t,n){var o=new PouchDB(n.localDB);if(c(e,t,o),e.$pouchdbRefs[t]=Object.create(null),v(e,t,o),n.remoteURL){u(e,t,o,new PouchDB(n.remoteURL))}},p=function(e,t,n){t in e||Vue.util.defineReactive(e,t,n)},h=function(e,t,n){n.change.docs.forEach(function(n){if(n._deleted)return void e.$options.pouchdb.uniques.forEach(function(o){e[t][o][n._id]&&Vue.delete(e[t][o],n._id)});e[t][n.doctype][n._id]=n})},v=function(e,t,n){e.$pouchdbRefs[t]=Object.create(null),e.$pouchdbRefs[t].put=r.bind({localDB:n,vm:e,key:t}),e.$pouchdbRefs[t].get=i.bind({localDB:n,vm:e,key:t}),e.$pouchdbRefs[t].update=f.bind({localDB:n,vm:e,key:t}),e.$pouchdbRefs[t].remove=a.bind({localDB:n,vm:e,key:t})};Vue.mixin({created:function(){s(this)}})}])});
|