vue-composable
Advanced tools
Comparing version 1.0.0-dev.1 to 1.0.0-dev.2
var vueComposable = (function (exports, compositionApi) { | ||
'use strict'; | ||
// export function unwrap<T>(o: RefTyped<T>): T { | ||
// return isRef(o) ? o.value : o; | ||
// } | ||
function unwrap(o) { | ||
return compositionApi.isRef(o) ? o.value : o; | ||
} | ||
function wrap(o) { | ||
@@ -19,2 +19,3 @@ return compositionApi.isRef(o) ? o : compositionApi.ref(o); | ||
const isObject = (val) => val !== null && typeof val === "object"; | ||
const isElement = (val) => isObject(val) && !!val.tagName; | ||
function isPromise(val) { | ||
@@ -411,3 +412,4 @@ return isObject(val) && isFunction(val.then) && isFunction(val.catch); | ||
} | ||
const remove = useEvent(element, "resize", handler, eventOptions); | ||
// resize seems only to be fired against the window | ||
const remove = useEvent(window, "resize", handler, eventOptions || { passive: true }); | ||
return { | ||
@@ -441,2 +443,74 @@ height, | ||
function useMatchMedia(query) { | ||
const mediaQueryList = compositionApi.ref(matchMedia(query)); | ||
const matches = compositionApi.ref(mediaQueryList.value.matches); | ||
const process = (e) => { | ||
matches.value = e.matches; | ||
}; | ||
mediaQueryList.value.addEventListener("change", process, { passive: true }); | ||
const remove = () => mediaQueryList.value.removeEventListener("change", process); | ||
compositionApi.onUnmounted(remove); | ||
return { | ||
mediaQueryList, | ||
remove, | ||
matches | ||
}; | ||
} | ||
function useBreakpoint(breakpoints) { | ||
const result = {}; | ||
const map = new Map(); | ||
const current = compositionApi.ref(); | ||
let sorted = []; | ||
const removeMedia = []; | ||
for (const key in breakpoints) { | ||
const bp = breakpoints[key]; | ||
if (isNumber(bp)) { | ||
const r = compositionApi.ref(false); | ||
result[key] = r; | ||
map.set(bp, { | ||
name: key, | ||
valid: r | ||
}); | ||
sorted.push(bp); | ||
} | ||
else { | ||
const { matches, remove } = useMatchMedia(bp); | ||
result[key] = matches; | ||
removeMedia.push(remove); | ||
} | ||
} | ||
sorted = sorted.sort((a, b) => b - a); | ||
const resize = () => { | ||
const width = window.innerWidth; | ||
let c = undefined; | ||
for (let i = 0; i < sorted.length; i++) { | ||
const bp = sorted[i]; | ||
const r = map.get(bp); | ||
r.valid.value = width >= bp; | ||
if (width >= bp && c === undefined) { | ||
c = r.name; | ||
} | ||
} | ||
current.value = c; | ||
}; | ||
const processResize = useDebounce(resize, 10); | ||
const remove = () => window.removeEventListener("resize", processResize); | ||
compositionApi.onMounted(() => { | ||
resize(); | ||
window.addEventListener("resize", processResize, { | ||
passive: true | ||
}); | ||
}); | ||
compositionApi.onUnmounted(() => { | ||
remove(); | ||
removeMedia.forEach(x => x()); | ||
}); | ||
return { | ||
...result, | ||
remove, | ||
current | ||
}; | ||
} | ||
function useFetch(options) { | ||
@@ -528,2 +602,75 @@ const json = compositionApi.ref(null); | ||
function useIntersectionObserver(refEl, refOptions) { | ||
const wrappedElement = refEl ? wrap(refEl) : undefined; | ||
const element = wrappedElement && (isElement(wrappedElement.value) || !wrappedElement.value) | ||
? wrappedElement | ||
: undefined; | ||
const options = compositionApi.computed(() => refOptions | ||
? unwrap(refOptions) | ||
: !element | ||
? unwrap(refEl) | ||
: undefined); | ||
const elements = compositionApi.ref(element && element.value ? [element.value] : []); | ||
const isIntersecting = compositionApi.computed(() => elements.value.length > 0 && elements.value.every(x => x.isIntersecting)); | ||
const handling = (entries) => { | ||
elements.value = entries; | ||
}; | ||
let observer = compositionApi.ref(); | ||
compositionApi.watch(options, options => { | ||
if (observer.value) { | ||
observer.value.disconnect(); | ||
} | ||
const opts = (options && | ||
options && { | ||
root: unwrap(options.root), | ||
rootMargin: unwrap(options.rootMargin), | ||
threshold: unwrap(options.threshold) | ||
}) || | ||
undefined; | ||
observer.value = new IntersectionObserver(handling, opts); | ||
const targets = elements.value.map(x => x.target); | ||
targets.forEach(observer.value.observe); | ||
}, { deep: true }); | ||
const observe = (element) => { | ||
const e = unwrap(element); | ||
observer.value.observe(e); | ||
}; | ||
const unobserve = (element) => { | ||
const e = unwrap(element); | ||
observer.value.unobserve(e); | ||
}; | ||
const disconnect = () => observer.value.disconnect(); | ||
// if the element is passed we should add hooks | ||
if (element) { | ||
// if value is defined it is already being observed | ||
if (!element.value) { | ||
compositionApi.onMounted(() => { | ||
if (element.value) { | ||
observe(element); | ||
} | ||
}); | ||
} | ||
compositionApi.onUnmounted(() => { | ||
disconnect(); | ||
}); | ||
} | ||
// // debug is still work in progress, would be nice to provide some | ||
// // information about the target | ||
// /* istanbul ignore next */ | ||
// const debug = () => { | ||
// if (elements.value.length === 0) { | ||
// (true !== 'production') && console.warn('[IntersectionObserver] no elements provided, did you mount the component?') | ||
// return; | ||
// } | ||
// // TODO: add border to the elements | ||
// }; | ||
return { | ||
elements, | ||
observe, | ||
unobserve, | ||
disconnect, | ||
isIntersecting | ||
}; | ||
} | ||
// used to store all the instances of weakMap | ||
@@ -593,2 +740,3 @@ const keyedMap = new Map(); | ||
exports.isDate = isDate; | ||
exports.isElement = isElement; | ||
exports.isFunction = isFunction; | ||
@@ -601,3 +749,5 @@ exports.isNumber = isNumber; | ||
exports.promisedTimeout = promisedTimeout; | ||
exports.unwrap = unwrap; | ||
exports.useArrayPagination = useArrayPagination; | ||
exports.useBreakpoint = useBreakpoint; | ||
exports.useCancellablePromise = useCancellablePromise; | ||
@@ -607,3 +757,5 @@ exports.useDebounce = useDebounce; | ||
exports.useFetch = useFetch; | ||
exports.useIntersectionObserver = useIntersectionObserver; | ||
exports.useLocalStorage = useLocalStorage; | ||
exports.useMatchMedia = useMatchMedia; | ||
exports.useOnMouseMove = useOnMouseMove; | ||
@@ -610,0 +762,0 @@ exports.useOnResize = useOnResize; |
@@ -1,1 +0,1 @@ | ||
var vueComposable=function(e,t){"use strict";function r(e){return t.isRef(e)?e:t.ref(e)}const n=Array.isArray,u=e=>"function"==typeof e,a=e=>l(e)&&u(e.getTime),o=e=>"number"==typeof e,l=e=>null!==e&&"object"==typeof e;function s(e){return l(e)&&u(e.then)&&u(e.catch)}function i(e){return new Promise(t=>{setTimeout(t,e)})}function c(e,t,r){return e<t?t:e>r?r:e}function v(e){const n=r(e.currentPage),u=r(e.pageSize),a=t.ref(0),o=r(e.total),l=t.computed({get:()=>a.value,set(e){"number"==typeof e?a.value=Math.min(e,o.value):console.warn(`[offset] expected number but got: '${typeof e}' value: '${e}'`)}}),s=t.computed({get:()=>n.value,set(e){"number"==typeof e?(n.value=c(e,1,v.value),l.value=(n.value-1)*i.value):console.warn(`[currentPage] expected number but got: '${typeof e}' value: '${e}'`)}}),i=t.computed({get:()=>u.value,set(e){"number"==typeof e?u.value=e:console.warn(`[pageSize] expected number but got: '${typeof e}' value: '${e}'`)}}),v=t.computed(()=>Math.ceil(o.value/i.value));s.value=n.value;return t.watch([o,i],()=>{s.value>v.value&&(s.value=v.value)},{lazy:!0}),{pageSize:i,total:o,currentPage:s,offset:l,lastPage:v,next:()=>++s.value,prev:()=>--s.value,first:()=>s.value=1,last:()=>s.value=v.value}}function f(e){if(!e)throw new Error(`[usePromise] argument can't be '${e}'`);if("function"!=typeof e)throw new Error(`[usePromise] expects function, but received ${typeof e}`);const r=t.ref(!1),n=t.ref(null),u=t.ref(null),a=t.ref();return{exec:async(...t)=>{r.value=!0,n.value=null,u.value=null;const o=a.value=e(...t);try{const e=await o;return a.value===o&&(u.value=e),e}catch(e){return void(a.value===o&&(n.value=e,u.value=null))}finally{a.value===o&&(r.value=!1)}},result:u,promise:a,loading:r,error:n}}const d=Symbol("RetryId"),m=Symbol("CancellationToken"),y=async(e,t,r,n)=>{const u=t[d].value;let l=-1;const c=e.maxRetries||9001,v=e.retryDelay||p;t.retryErrors.value=[],t.isRetrying.value=!1,t.nextRetry.value=void 0;let f=void 0;do{let e=!1,y=null;try{if(++l,y=n?r(...n):r(),s(y)&&(y=await y),t[m].value)return null;e=!0}catch(e){y=null,t.retryErrors.value.push(e)}if(u!==t[d].value)return y;if(e)return t.isRetrying.value=!1,t.nextRetry.value=void 0,y;if(l>=c)return t.isRetrying.value=!1,t.nextRetry.value=void 0,Promise.reject(new Error(`[useRetry] max retries reached ${c}`));t.isRetrying.value=!0;const p=Date.now(),g=v(l),h=s(g)?await g:g;if(!s(g)||h){if(o(h))f=h;else{if(!a(h))throw new Error(`[useRetry] invalid value received from options.retryDelay '${typeof h}'`);f=h.getTime()}f<p?t.nextRetry.value=p+f:(t.nextRetry.value=f,f-=p),f>0&&await i(f)}if(t[m].value)return null;if(u!==t[d].value)return y}while(l<9e3);return null};const p=()=>0;function g(e,t){return h(e,t)}function h(e,t=50,r={isImmediate:!1}){let n;return function(...u){const a=this,o=r.isImmediate&&void 0===n;void 0!==n&&clearTimeout(n),n=setTimeout((function(){n=void 0,r.isImmediate||e.apply(a,u)}),t),o&&e.apply(a,u)}}function w(e,n,u,a){const o=r(e),l=()=>o.value.removeEventListener(n,u);return t.onMounted(()=>o.value.addEventListener(n,u,a)),t.onUnmounted(l),l}const b=new Map,E=new WeakMap;return e.debounce=h,e.exponentialDelay=e=>{const t=100*Math.pow(2,e);return t+.2*t*Math.random()},e.isArray=n,e.isDate=a,e.isFunction=u,e.isNumber=o,e.isObject=l,e.isPromise=s,e.minMax=c,e.noDelay=p,e.promisedTimeout=i,e.useArrayPagination=function(e,n){const u=r(e),a=v({currentPage:1,pageSize:10,...n,total:t.computed(()=>u.value.length)}),o=t.computed(()=>{const e=u.value;return Array.isArray(e)?e.slice(a.offset.value,a.offset.value+a.pageSize.value):[]});return{...a,result:o}},e.useCancellablePromise=function(e){const r=t.ref(!1);let n=void 0;return{...f((...t)=>(e=>new Promise((t,u)=>{n=e=>{r.value=!0,u(e)},e.then(t).catch(u)}))(e(...t))),cancel:e=>n(e),cancelled:r}},e.useDebounce=g,e.useEvent=w,e.useFetch=function(e){const r=t.ref(null),n=t.ref(null),u=!e||!1!==e.isJson,a=!e||!1!==e.parseImmediate,o=f(async(e,t)=>{const o=await fetch(e,t);if(u){const e=o.json().then(e=>r.value=e).catch(e=>{r.value=null,n.value=e});a&&await e}return o}),l=t.computed(()=>o.result.value&&o.result.value.status||null),s=t.computed(()=>o.result.value&&o.result.value.statusText||null);return{...o,json:r,jsonError:n,status:l,statusText:s}},e.useLocalStorage=function(e,n){let u=!1,a=b.get(e);const o=localStorage.getItem(e),l=a&&E.get(a)||!!n&&r(n)||t.ref(null);if(o&&!a)try{l.value=JSON.parse(o),u=!1}catch(t){console.warn("[useLocalStorage] error parsing value from localStorage",e,t)}return a||(a={},b.set(e,a),E.set(a,l),t.watch(l,t=>{void 0!==t?h(()=>localStorage.setItem(e,JSON.stringify(t)),100)():localStorage.removeItem(e)},{deep:!0,lazy:u})),{storage:l,clear:()=>{b.forEach(e=>{const t=E.get(e);t&&(t.value=void 0),E.delete(e)}),b.clear()},remove:()=>{b.delete(e),E.delete(a),l.value=void 0}}},e.useOnMouseMove=function(e,r,n){const u=t.ref(0),a=t.ref(0);let o=e=>{u.value=e.x,a.value=e.y};const l="number"==typeof r?void 0:r;("number"==typeof r?r:n)&&(o=g(o,n));const s=w(e,"mousemove",o,l);return{mouseX:u,mouseY:a,remove:s}},e.useOnResize=function(e,n,u){const a=r(e),o=t.ref(a.value&&a.value.clientHeight),l=t.ref(a.value&&a.value.clientWidth);let s=()=>{o.value=a.value.clientHeight,l.value=a.value.clientWidth};const i="number"==typeof n?void 0:n;("number"==typeof n?n:u)&&(s=g(s,u));const c=w(a,"resize",s,i);return{height:o,width:l,remove:c}},e.useOnScroll=function(e,n,u){const a=r(e),o=t.ref(a.value&&a.value.scrollTop),l=t.ref(a.value&&a.value.scrollLeft);let s=e=>{o.value=a.value.scrollTop,l.value=a.value.scrollLeft};const i="number"==typeof n?void 0:n;("number"==typeof n?n:u)&&(s=g(s,u));const c=w(a,"scroll",s,i);return{scrollTop:o,scrollLeft:l,remove:c}},e.usePagination=v,e.usePromise=f,e.useRetry=function(e,r){const n=!e||u(e)?{}:e,a=u(e)?e:r;if(!u(e)&&!l(e))throw new Error("[useRetry] options needs to be 'object'");if(a&&!u(a))throw new Error("[useRetry] factory needs to be 'function'");const o=t.ref(!1),s=t.ref(),i=t.ref([]),c={value:!1},v={isRetrying:o,retryCount:t.computed(()=>i.value.length),nextRetry:s,retryErrors:i,[d]:{value:0},[m]:c},f=a?(...e)=>(++v[d].value,y(n,v,a,e)):e=>(++v[d].value,y(n,v,e,void 0));return{...v,cancel:()=>{v.isRetrying.value=!1,v.retryErrors.value.push(new Error("[useRetry] cancelled")),v.nextRetry.value=void 0,c.value=!0},exec:f}},e.useWebSocket=function(e,r){const n=new WebSocket(e,r),u=t.ref(null),a=t.ref(),o=t.ref(null),l=t.ref(!1),s=t.ref(!1),i=t.ref(!1);let c=Date.now()||void 0;return n.addEventListener("message",e=>{u.value=e,o.value=e.data,Date.now()-c<2&&console.warn('[useWebSocket] message rate is too high, if you are using "data" or "messageEvent" you might not get updated of all the messages. Use "ws..addEventListener("message", handler)" instead'),c=Date.now()}),n.addEventListener("error",e=>{a.value=e,i.value=!0}),n.addEventListener("close",()=>{l.value=!1,s.value=!0}),n.addEventListener("open",()=>{l.value=!0,s.value=!1}),{ws:n,send:e=>n.send(e),close:(e,t)=>{n.close(e,t)},messageEvent:u,errorEvent:a,data:o,isOpen:l,isClosed:s,errored:i}},e.wrap=r,e}({},vueCompositionApi); | ||
var vueComposable=function(e,t){"use strict";function n(e){return t.isRef(e)?e.value:e}function r(e){return t.isRef(e)?e:t.ref(e)}const o=Array.isArray,u=e=>"function"==typeof e,a=e=>s(e)&&u(e.getTime),l=e=>"number"==typeof e,s=e=>null!==e&&"object"==typeof e,i=e=>s(e)&&!!e.tagName;function v(e){return s(e)&&u(e.then)&&u(e.catch)}function c(e){return new Promise(t=>{setTimeout(t,e)})}function f(e,t,n){return e<t?t:e>n?n:e}function d(e){const n=r(e.currentPage),o=r(e.pageSize),u=t.ref(0),a=r(e.total),l=t.computed({get:()=>u.value,set(e){"number"==typeof e?u.value=Math.min(e,a.value):console.warn(`[offset] expected number but got: '${typeof e}' value: '${e}'`)}}),s=t.computed({get:()=>n.value,set(e){"number"==typeof e?(n.value=f(e,1,v.value),l.value=(n.value-1)*i.value):console.warn(`[currentPage] expected number but got: '${typeof e}' value: '${e}'`)}}),i=t.computed({get:()=>o.value,set(e){"number"==typeof e?o.value=e:console.warn(`[pageSize] expected number but got: '${typeof e}' value: '${e}'`)}}),v=t.computed(()=>Math.ceil(a.value/i.value));s.value=n.value;return t.watch([a,i],()=>{s.value>v.value&&(s.value=v.value)},{lazy:!0}),{pageSize:i,total:a,currentPage:s,offset:l,lastPage:v,next:()=>++s.value,prev:()=>--s.value,first:()=>s.value=1,last:()=>s.value=v.value}}function m(e){if(!e)throw new Error(`[usePromise] argument can't be '${e}'`);if("function"!=typeof e)throw new Error(`[usePromise] expects function, but received ${typeof e}`);const n=t.ref(!1),r=t.ref(null),o=t.ref(null),u=t.ref();return{exec:async(...t)=>{n.value=!0,r.value=null,o.value=null;const a=u.value=e(...t);try{const e=await a;return u.value===a&&(o.value=e),e}catch(e){return void(u.value===a&&(r.value=e,o.value=null))}finally{u.value===a&&(n.value=!1)}},result:o,promise:u,loading:n,error:r}}const p=Symbol("RetryId"),y=Symbol("CancellationToken"),g=async(e,t,n,r)=>{const o=t[p].value;let u=-1;const s=e.maxRetries||9001,i=e.retryDelay||h;t.retryErrors.value=[],t.isRetrying.value=!1,t.nextRetry.value=void 0;let f=void 0;do{let e=!1,d=null;try{if(++u,d=r?n(...r):n(),v(d)&&(d=await d),t[y].value)return null;e=!0}catch(e){d=null,t.retryErrors.value.push(e)}if(o!==t[p].value)return d;if(e)return t.isRetrying.value=!1,t.nextRetry.value=void 0,d;if(u>=s)return t.isRetrying.value=!1,t.nextRetry.value=void 0,Promise.reject(new Error(`[useRetry] max retries reached ${s}`));t.isRetrying.value=!0;const m=Date.now(),g=i(u),h=v(g)?await g:g;if(!v(g)||h){if(l(h))f=h;else{if(!a(h))throw new Error(`[useRetry] invalid value received from options.retryDelay '${typeof h}'`);f=h.getTime()}f<m?t.nextRetry.value=m+f:(t.nextRetry.value=f,f-=m),f>0&&await c(f)}if(t[y].value)return null;if(o!==t[p].value)return d}while(u<9e3);return null};const h=()=>0;function w(e,t){return b(e,t)}function b(e,t=50,n={isImmediate:!1}){let r;return function(...o){const u=this,a=n.isImmediate&&void 0===r;void 0!==r&&clearTimeout(r),r=setTimeout((function(){r=void 0,n.isImmediate||e.apply(u,o)}),t),a&&e.apply(u,o)}}function E(e,n,o,u){const a=r(e),l=()=>a.value.removeEventListener(n,o);return t.onMounted(()=>a.value.addEventListener(n,o,u)),t.onUnmounted(l),l}function R(e){const n=t.ref(matchMedia(e)),r=t.ref(n.value.matches),o=e=>{r.value=e.matches};n.value.addEventListener("change",o,{passive:!0});const u=()=>n.value.removeEventListener("change",o);return t.onUnmounted(u),{mediaQueryList:n,remove:u,matches:r}}const x=new Map,S=new WeakMap;return e.debounce=b,e.exponentialDelay=e=>{const t=100*Math.pow(2,e);return t+.2*t*Math.random()},e.isArray=o,e.isDate=a,e.isElement=i,e.isFunction=u,e.isNumber=l,e.isObject=s,e.isPromise=v,e.minMax=f,e.noDelay=h,e.promisedTimeout=c,e.unwrap=n,e.useArrayPagination=function(e,n){const o=r(e),u=d({currentPage:1,pageSize:10,...n,total:t.computed(()=>o.value.length)}),a=t.computed(()=>{const e=o.value;return Array.isArray(e)?e.slice(u.offset.value,u.offset.value+u.pageSize.value):[]});return{...u,result:a}},e.useBreakpoint=function(e){const n={},r=new Map,o=t.ref();let u=[];const a=[];for(const o in e){const s=e[o];if(l(s)){const e=t.ref(!1);n[o]=e,r.set(s,{name:o,valid:e}),u.push(s)}else{const{matches:e,remove:t}=R(s);n[o]=e,a.push(t)}}u=u.sort((e,t)=>t-e);const s=()=>{const e=window.innerWidth;let t=void 0;for(let n=0;n<u.length;n++){const o=u[n],a=r.get(o);a.valid.value=e>=o,e>=o&&void 0===t&&(t=a.name)}o.value=t},i=w(s,10),v=()=>window.removeEventListener("resize",i);return t.onMounted(()=>{s(),window.addEventListener("resize",i,{passive:!0})}),t.onUnmounted(()=>{v(),a.forEach(e=>e())}),{...n,remove:v,current:o}},e.useCancellablePromise=function(e){const n=t.ref(!1);let r=void 0;return{...m((...t)=>(e=>new Promise((t,o)=>{r=e=>{n.value=!0,o(e)},e.then(t).catch(o)}))(e(...t))),cancel:e=>r(e),cancelled:n}},e.useDebounce=w,e.useEvent=E,e.useFetch=function(e){const n=t.ref(null),r=t.ref(null),o=!e||!1!==e.isJson,u=!e||!1!==e.parseImmediate,a=m(async(e,t)=>{const a=await fetch(e,t);if(o){const e=a.json().then(e=>n.value=e).catch(e=>{n.value=null,r.value=e});u&&await e}return a}),l=t.computed(()=>a.result.value&&a.result.value.status||null),s=t.computed(()=>a.result.value&&a.result.value.statusText||null);return{...a,json:n,jsonError:r,status:l,statusText:s}},e.useIntersectionObserver=function(e,o){const u=e?r(e):void 0,a=!u||!i(u.value)&&u.value?void 0:u,l=t.computed(()=>o?n(o):a?void 0:n(e)),s=t.ref(a&&a.value?[a.value]:[]),v=t.computed(()=>s.value.length>0&&s.value.every(e=>e.isIntersecting)),c=e=>{s.value=e};let f=t.ref();t.watch(l,e=>{f.value&&f.value.disconnect();const t=e&&e&&{root:n(e.root),rootMargin:n(e.rootMargin),threshold:n(e.threshold)}||void 0;f.value=new IntersectionObserver(c,t),s.value.map(e=>e.target).forEach(f.value.observe)},{deep:!0});const d=e=>{const t=n(e);f.value.observe(t)},m=()=>f.value.disconnect();return a&&(a.value||t.onMounted(()=>{a.value&&d(a)}),t.onUnmounted(()=>{m()})),{elements:s,observe:d,unobserve:e=>{const t=n(e);f.value.unobserve(t)},disconnect:m,isIntersecting:v}},e.useLocalStorage=function(e,n){let o=!1,u=x.get(e);const a=localStorage.getItem(e),l=u&&S.get(u)||!!n&&r(n)||t.ref(null);if(a&&!u)try{l.value=JSON.parse(a),o=!1}catch(t){console.warn("[useLocalStorage] error parsing value from localStorage",e,t)}return u||(u={},x.set(e,u),S.set(u,l),t.watch(l,t=>{void 0!==t?b(()=>localStorage.setItem(e,JSON.stringify(t)),100)():localStorage.removeItem(e)},{deep:!0,lazy:o})),{storage:l,clear:()=>{x.forEach(e=>{const t=S.get(e);t&&(t.value=void 0),S.delete(e)}),x.clear()},remove:()=>{x.delete(e),S.delete(u),l.value=void 0}}},e.useMatchMedia=R,e.useOnMouseMove=function(e,n,r){const o=t.ref(0),u=t.ref(0);let a=e=>{o.value=e.x,u.value=e.y};const l="number"==typeof n?void 0:n;("number"==typeof n?n:r)&&(a=w(a,r));const s=E(e,"mousemove",a,l);return{mouseX:o,mouseY:u,remove:s}},e.useOnResize=function(e,n,o){const u=r(e),a=t.ref(u.value&&u.value.clientHeight),l=t.ref(u.value&&u.value.clientWidth);let s=()=>{a.value=u.value.clientHeight,l.value=u.value.clientWidth};const i="number"==typeof n?void 0:n;("number"==typeof n?n:o)&&(s=w(s,o));const v=E(window,"resize",s,i||{passive:!0});return{height:a,width:l,remove:v}},e.useOnScroll=function(e,n,o){const u=r(e),a=t.ref(u.value&&u.value.scrollTop),l=t.ref(u.value&&u.value.scrollLeft);let s=e=>{a.value=u.value.scrollTop,l.value=u.value.scrollLeft};const i="number"==typeof n?void 0:n;("number"==typeof n?n:o)&&(s=w(s,o));const v=E(u,"scroll",s,i);return{scrollTop:a,scrollLeft:l,remove:v}},e.usePagination=d,e.usePromise=m,e.useRetry=function(e,n){const r=!e||u(e)?{}:e,o=u(e)?e:n;if(!u(e)&&!s(e))throw new Error("[useRetry] options needs to be 'object'");if(o&&!u(o))throw new Error("[useRetry] factory needs to be 'function'");const a=t.ref(!1),l=t.ref(),i=t.ref([]),v={value:!1},c={isRetrying:a,retryCount:t.computed(()=>i.value.length),nextRetry:l,retryErrors:i,[p]:{value:0},[y]:v},f=o?(...e)=>(++c[p].value,g(r,c,o,e)):e=>(++c[p].value,g(r,c,e,void 0));return{...c,cancel:()=>{c.isRetrying.value=!1,c.retryErrors.value.push(new Error("[useRetry] cancelled")),c.nextRetry.value=void 0,v.value=!0},exec:f}},e.useWebSocket=function(e,n){const r=new WebSocket(e,n),o=t.ref(null),u=t.ref(),a=t.ref(null),l=t.ref(!1),s=t.ref(!1),i=t.ref(!1);let v=Date.now()||void 0;return r.addEventListener("message",e=>{o.value=e,a.value=e.data,Date.now()-v<2&&console.warn('[useWebSocket] message rate is too high, if you are using "data" or "messageEvent" you might not get updated of all the messages. Use "ws..addEventListener("message", handler)" instead'),v=Date.now()}),r.addEventListener("error",e=>{u.value=e,i.value=!0}),r.addEventListener("close",()=>{l.value=!1,s.value=!0}),r.addEventListener("open",()=>{l.value=!0,s.value=!1}),{ws:r,send:e=>r.send(e),close:(e,t)=>{r.close(e,t)},messageEvent:o,errorEvent:u,data:a,isOpen:l,isClosed:s,errored:i}},e.wrap=r,e}({},vueCompositionApi); |
{ | ||
"name": "vue-composable", | ||
"version": "1.0.0-dev.1", | ||
"version": "1.0.0-dev.2", | ||
"description": "vue-composable", | ||
@@ -28,3 +28,6 @@ "main": "index.js", | ||
"keywords": [ | ||
"vue" | ||
"vue", | ||
"composition-api", | ||
"vue-composable", | ||
"composable" | ||
], | ||
@@ -37,5 +40,5 @@ "author": "pikax", | ||
"homepage": "https://github.com/pikax/vue-composable", | ||
"dependencies": { | ||
"@vue-composable/core": "^1.0.0-dev.0", | ||
"@vue-composable/web": "^1.0.0-dev.0", | ||
"peerDependencies": { | ||
"@vue-composable/core": "^1.0.0-dev.2", | ||
"@vue-composable/web": "^1.0.0-dev.2", | ||
"@vue/composition-api": "^0.3.4", | ||
@@ -42,0 +45,0 @@ "vue": "^2.6.10" |
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
43259
11
813
0
121
- Removed@vue-composable/core@^1.0.0-dev.0
- Removed@vue-composable/web@^1.0.0-dev.0
- Removed@vue/composition-api@^0.3.4
- Removedvue@^2.6.10