UNPKG

vue-composable-helpers

Version:

Vue 3 composable api helpers

3 lines (2 loc) 2.23 kB
import e from"json2mq";import{ref as r,computed as n,onMounted as t,onBeforeUnmount as o}from"vue";function i(e,r){return function(e){if(Array.isArray(e))return e}(e)||function(e,r){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(e)))return;var n=[],t=!0,o=!1,i=void 0;try{for(var a,u=e[Symbol.iterator]();!(t=(a=u.next()).done)&&(n.push(a.value),!r||n.length!==r);t=!0);}catch(e){o=!0,i=e}finally{try{t||null==u.return||u.return()}finally{if(o)throw i}}return n}(e,r)||function(e,r){if(!e)return;if("string"==typeof e)return a(e,r);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return a(e,r)}(e,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function a(e,r){(null==r||r>e.length)&&(r=e.length);for(var n=0,t=new Array(r);n<r;n++)t[n]=e[n];return t}function u(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:void 0,t=r(e),o=n((function(){return t.value}));function i(e){t.value=e}return[o,i]}function l(n){var a=arguments.length>1&&void 0!==arguments[1]&&arguments[1],l=e(n),c=r(),f=u(a),v=i(f,2),s=v[0],m=v[1],d=u(""),h=i(d,2),y=h[0],p=h[1],b=u(!1),g=i(b,2),S=g[0],w=g[1];function A(e){m(e.matches),p(e.media)}function E(){if(c.value=window.matchMedia(l),m(c.value.matches),p(c.value.media),!c.value)return w(!0);c.value.addEventListener?c.value.addEventListener("change",A):c.value.addListener(A)}function L(){c.value&&(c.value.removeEventListener?c.value.removeEventListener("change",A):c.value.removeListener(A))}return t(E),o(L),{error:S,matches:s,media:y}}function c(e){var r=i(u(!1),2),n=r[0],t=r[1],o=i(u(!0),2),a=o[0],l=o[1],c=i(u(!1),2),f=c[0],v=c[1],s=i(u(null),2),m=s[0],d=s[1],h=i(u(null),2),y=h[0],p=h[1];return e.then((function(e){d(e),v(!0)})),e.catch((function(e){p(e),t(!0)})),e.finally((function(){l(!1)})),{data:m,error:y,isError:n,isPending:a,isSuccess:f}}export{u as useComputedState,l as useMatchMedia,c as usePromise}; //# sourceMappingURL=vue-composable-helpers-esm.js.map