UNPKG

@apicart/vue-components

Version:

Apicart Vue.Js components for simple e-commerce platform development

8 lines (6 loc) 3.85 kB
/** * @apicart/vue-components v1.0.0-alpha7 * (c) 2018-2020 Apicart Company * Released under the MIT License. */ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("@apicart/core-sdk")):"function"==typeof define&&define.amd?define(["@apicart/core-sdk"],e):(t=t||self).ApicartProductsDownloader=e(t.Apicart)}(this,(function(t){"use strict";function e(t,e,r,a){return new(r||(r=Promise))((function(o,n){function u(t){try{l(a.next(t))}catch(t){n(t)}}function i(t){try{l(a.throw(t))}catch(t){n(t)}}function l(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(u,i)}l((a=a.apply(t,e||[])).next())}))}function r(t,e){var r,a,o,n,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return n={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(n[Symbol.iterator]=function(){return this}),n;function i(n){return function(i){return function(n){if(r)throw new TypeError("Generator is already executing.");for(;u;)try{if(r=1,a&&(o=2&n[0]?a.return:n[0]?a.throw||((o=a.return)&&o.call(a),0):a.next)&&!(o=o.call(a,n[1])).done)return o;switch(a=0,o&&(n=[2&n[0],o.value]),n[0]){case 0:case 1:o=n;break;case 4:return u.label++,{value:n[1],done:!1};case 5:u.label++,a=n[1],n=[0];continue;case 7:n=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==n[0]&&2!==n[0])){u=0;continue}if(3===n[0]&&(!o||n[1]>o[0]&&n[1]<o[3])){u.label=n[1];break}if(6===n[0]&&u.label<o[1]){u.label=o[1],o=n;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(n);break}o[2]&&u.ops.pop(),u.trys.pop();continue}n=e.call(t,u)}catch(t){n=[6,t],a=0}finally{r=o=0}if(5&n[0])throw n[1];return{value:n[0]?n[1]:void 0,done:!0}}([n,i])}}}return t=t&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t,new(function(){function a(){this._localStorage=t.Storage,this._storageName="apicart-products-files",this._loadedProducts={},this._loadedProducts=this.getStorage()}return a.prototype.getStorageName=function(){return this._storageName},a.prototype.getStorage=function(){return this._localStorage.getItem(this.getStorageName())||{}},a.prototype.getLoadedProducts=function(){return this._loadedProducts},a.prototype.getLoadedProductsData=function(e){var r=this,a=[];return t.Utils.Loops.forEach(e,(function(t){var e=t,o=null,n=null;"string"!=typeof t&&(e=t.dataUrl,o=t.pageUrl,t.data&&Object.keys(t.data).length&&(n=t.data)),(n||e in r._loadedProducts)&&a.push({dataUrl:e,data:n||r._loadedProducts[e].data,pageUrl:o||r._loadedProducts[e].pageUrl})})),a},a.prototype.getProductsData=function(a){return e(this,void 0,void 0,(function(){var o,n,u,i,l=this;return r(this,(function(s){switch(s.label){case 0:return o=t.Storage,n=[],t.Utils.Loops.forEach(a,(function(a){var o=a,u=null,i=null;"string"!=typeof a&&(o=a.dataUrl,u=a.pageUrl,i=a.data||null);var s=i&&0!==Object.keys(i).length;o in l._loadedProducts||s?n.push(Promise.resolve({dataUrl:o,data:s?i:l._loadedProducts[o].data,pageUrl:u})):n.push(e(l,void 0,void 0,(function(){var e;return r(this,(function(r){switch(r.label){case 0:return[4,t.Utils.Ajax.get(o)];case 1:return"object"!=typeof(e=r.sent())||200!==parseInt(e.status)?[2]:[2,{dataUrl:o,data:e.data,pageUrl:u}]}}))})))})),[4,Promise.all(n)];case 1:return u=s.sent(),i=[],t.Utils.Loops.forEach(u,(function(t){t&&(l._loadedProducts[t.dataUrl]={data:t.data,pageUrl:t.pageUrl},i.push(t))})),o.setItem(this._storageName,this._loadedProducts),[2,i]}}))}))},a.prototype.getProductData=function(t){return e(this,void 0,void 0,(function(){var e;return r(this,(function(r){switch(r.label){case 0:return[4,this.getProductsData([t])];case 1:return[2,0===(e=r.sent()).length||void 0===e[0]?null:e[0].data]}}))}))},a.prototype.getLoadedProductData=function(t){var e=this.getLoadedProductsData([t]);return 1===e.length?e[0]:null},a}())}));