@vueuse/shared
Advanced tools
Comparing version 4.0.0-beta.34 to 4.0.0-beta.35
@@ -7,6 +7,26 @@ 'use strict'; | ||
function biSyncRef(a, b) { | ||
const flush = 'sync'; | ||
const stop1 = vueDemi.watch(a, (newValue) => { | ||
b.value = newValue; | ||
}, { | ||
flush, | ||
immediate: true, | ||
}); | ||
const stop2 = vueDemi.watch(b, (newValue) => { | ||
a.value = newValue; | ||
}, { | ||
flush, | ||
immediate: true, | ||
}); | ||
return () => { | ||
stop1(); | ||
stop2(); | ||
}; | ||
} | ||
/** | ||
* Explicitly define the deps of computed | ||
* | ||
* @param effects | ||
* @param source | ||
* @param fn | ||
@@ -16,11 +36,14 @@ */ | ||
const v = vueDemi.ref(fn()); | ||
vueDemi.watch(source, () => v.value = fn()); | ||
vueDemi.watch(source, () => v.value = fn(), { | ||
flush: 'sync', | ||
}); | ||
return vueDemi.computed(() => v.value); | ||
} | ||
function extendRef(ref, extend, enumerable = true) { | ||
// implementation | ||
function extendRef(ref, extend, { enumerable = false, unwrap = true } = {}) { | ||
for (const [key, value] of Object.entries(extend)) { | ||
if (key === 'value') | ||
continue; | ||
if (vueDemi.isRef(value)) { | ||
if (vueDemi.isRef(value) && unwrap) { | ||
Object.defineProperty(ref, key, { | ||
@@ -209,2 +232,3 @@ get() { | ||
exports.assert = assert; | ||
exports.biSyncRef = biSyncRef; | ||
exports.clamp = clamp; | ||
@@ -211,0 +235,0 @@ exports.controlledComputed = controlledComputed; |
@@ -0,8 +1,10 @@ | ||
import { Ref, WatchSource, ShallowUnwrapRef, WatchOptions } from 'vue-demi'; | ||
import { ComputedRef, WatchStopHandle } from 'vue-demi'; | ||
import { WatchSource, Ref, ShallowUnwrapRef, WatchOptions } from 'vue-demi'; | ||
declare function biSyncRef<R extends Ref<any>>(a: R, b: R): () => void; | ||
/** | ||
* Explicitly define the deps of computed | ||
* | ||
* @param effects | ||
* @param source | ||
* @param fn | ||
@@ -12,3 +14,24 @@ */ | ||
declare function extendRef<R extends Ref<any>, Extend extends object>(ref: R, extend: Extend, enumerable?: boolean): ShallowUnwrapRef<Extend> & R; | ||
interface ExtendRefOptions<Unwrap extends boolean = boolean> { | ||
/** | ||
* Is the extends properties enumerable | ||
* | ||
* @default false | ||
*/ | ||
enumerable?: boolean; | ||
/** | ||
* Unwrap for Ref properties | ||
* | ||
* @default true | ||
*/ | ||
unwrap?: Unwrap; | ||
} | ||
/** | ||
* Overlad 1: Unwrap set to false | ||
*/ | ||
declare function extendRef<R extends Ref<any>, Extend extends object, Options extends ExtendRefOptions<false>>(ref: R, extend: Extend, options: Options): ShallowUnwrapRef<Extend> & R; | ||
/** | ||
* Overlad 2: Unwrap unset or set to true | ||
*/ | ||
declare function extendRef<R extends Ref<any>, Extend extends object, Options extends ExtendRefOptions>(ref: R, extend: Extend, options: Options): Extend & R; | ||
@@ -97,2 +120,2 @@ declare function makeDestructurable<T extends Record<string, unknown>, A extends readonly any[]>(obj: T, arr: A): T & A; | ||
export { MaybeRef, SyncRefOptions, WhenInstance, WhenToMatchOptions, assert, clamp, controlledComputed, extendRef, invoke, isBoolean, isClient, isDef, isFunction, isNumber, isObject, isString, isWindow, makeDestructurable, noop, now, promiseTimeout, syncRef, timestamp, tryOnMounted, tryOnUnmounted, when }; | ||
export { ExtendRefOptions, MaybeRef, SyncRefOptions, WhenInstance, WhenToMatchOptions, assert, biSyncRef, clamp, controlledComputed, extendRef, invoke, isBoolean, isClient, isDef, isFunction, isNumber, isObject, isString, isWindow, makeDestructurable, noop, now, promiseTimeout, syncRef, timestamp, tryOnMounted, tryOnUnmounted, when }; |
@@ -1,7 +0,27 @@ | ||
import { ref, watch, computed, isRef, getCurrentInstance, onMounted, nextTick, onUnmounted } from 'vue-demi'; | ||
import { watch, ref, computed, isRef, getCurrentInstance, onMounted, nextTick, onUnmounted } from 'vue-demi'; | ||
function biSyncRef(a, b) { | ||
const flush = 'sync'; | ||
const stop1 = watch(a, (newValue) => { | ||
b.value = newValue; | ||
}, { | ||
flush, | ||
immediate: true, | ||
}); | ||
const stop2 = watch(b, (newValue) => { | ||
a.value = newValue; | ||
}, { | ||
flush, | ||
immediate: true, | ||
}); | ||
return () => { | ||
stop1(); | ||
stop2(); | ||
}; | ||
} | ||
/** | ||
* Explicitly define the deps of computed | ||
* | ||
* @param effects | ||
* @param source | ||
* @param fn | ||
@@ -11,11 +31,14 @@ */ | ||
const v = ref(fn()); | ||
watch(source, () => v.value = fn()); | ||
watch(source, () => v.value = fn(), { | ||
flush: 'sync', | ||
}); | ||
return computed(() => v.value); | ||
} | ||
function extendRef(ref, extend, enumerable = true) { | ||
// implementation | ||
function extendRef(ref, extend, { enumerable = false, unwrap = true } = {}) { | ||
for (const [key, value] of Object.entries(extend)) { | ||
if (key === 'value') | ||
continue; | ||
if (isRef(value)) { | ||
if (isRef(value) && unwrap) { | ||
Object.defineProperty(ref, key, { | ||
@@ -203,2 +226,2 @@ get() { | ||
export { assert, clamp, controlledComputed, extendRef, invoke, isBoolean, isClient, isDef, isFunction, isNumber, isObject, isString, isWindow, makeDestructurable, noop, now, promiseTimeout, syncRef, timestamp, tryOnMounted, tryOnUnmounted, when }; | ||
export { assert, biSyncRef, clamp, controlledComputed, extendRef, invoke, isBoolean, isClient, isDef, isFunction, isNumber, isObject, isString, isWindow, makeDestructurable, noop, now, promiseTimeout, syncRef, timestamp, tryOnMounted, tryOnUnmounted, when }; |
@@ -7,6 +7,26 @@ (function (global, factory) { | ||
function biSyncRef(a, b) { | ||
const flush = 'sync'; | ||
const stop1 = vueDemi.watch(a, (newValue) => { | ||
b.value = newValue; | ||
}, { | ||
flush, | ||
immediate: true, | ||
}); | ||
const stop2 = vueDemi.watch(b, (newValue) => { | ||
a.value = newValue; | ||
}, { | ||
flush, | ||
immediate: true, | ||
}); | ||
return () => { | ||
stop1(); | ||
stop2(); | ||
}; | ||
} | ||
/** | ||
* Explicitly define the deps of computed | ||
* | ||
* @param effects | ||
* @param source | ||
* @param fn | ||
@@ -16,11 +36,14 @@ */ | ||
const v = vueDemi.ref(fn()); | ||
vueDemi.watch(source, () => v.value = fn()); | ||
vueDemi.watch(source, () => v.value = fn(), { | ||
flush: 'sync', | ||
}); | ||
return vueDemi.computed(() => v.value); | ||
} | ||
function extendRef(ref, extend, enumerable = true) { | ||
// implementation | ||
function extendRef(ref, extend, { enumerable = false, unwrap = true } = {}) { | ||
for (const [key, value] of Object.entries(extend)) { | ||
if (key === 'value') | ||
continue; | ||
if (vueDemi.isRef(value)) { | ||
if (vueDemi.isRef(value) && unwrap) { | ||
Object.defineProperty(ref, key, { | ||
@@ -209,2 +232,3 @@ get() { | ||
exports.assert = assert; | ||
exports.biSyncRef = biSyncRef; | ||
exports.clamp = clamp; | ||
@@ -211,0 +235,0 @@ exports.controlledComputed = controlledComputed; |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue-demi")):"function"==typeof define&&define.amd?define(["exports","vue-demi"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["VueUseShared utilities"]={},e.VueDemi)}(this,(function(e,t){"use strict";const n="undefined"!=typeof window,o=Object.prototype.toString;function u(e,t=!1,n="Timeout"){return new Promise(((o,u)=>{t?setTimeout((()=>u(n)),e):setTimeout(o,e)}))}e.assert=(e,...t)=>{e||console.warn(...t)},e.clamp=(e,t,n)=>Math.min(n,Math.max(t,e)),e.controlledComputed=function(e,n){const o=t.ref(n());return t.watch(e,(()=>o.value=n())),t.computed((()=>o.value))},e.extendRef=function(e,n,o=!0){for(const[u,i]of Object.entries(n))"value"!==u&&(t.isRef(i)?Object.defineProperty(e,u,{get:()=>i.value,set(e){i.value=e},enumerable:o}):Object.defineProperty(e,u,{value:i,enumerable:o}));return e},e.invoke=function(e){return e()},e.isBoolean=e=>"boolean"==typeof e,e.isClient=n,e.isDef=e=>void 0!==e,e.isFunction=e=>"function"==typeof e,e.isNumber=e=>"number"==typeof e,e.isObject=e=>"[object Object]"===o.call(e),e.isString=e=>"string"==typeof e,e.isWindow=e=>"undefined"!=typeof window&&"[object Window]"===o.call(e),e.makeDestructurable=function(e,t){if("undefined"!=typeof Symbol){const n=Object.assign({},e);return Object.defineProperty(n,Symbol.iterator,{enumerable:!1,value(){let e=0;return{next:()=>({value:t[e++],done:e>t.length})}}}),n}return Object.assign([...t],e)},e.noop=()=>{},e.now=()=>Date.now(),e.promiseTimeout=u,e.syncRef=function(e,n,{flush:o="sync",deep:u=!1,immediate:i=!0}={}){return Array.isArray(n)||(n=[n]),t.watch(e,(e=>{n.forEach((t=>t.value=e))}),{flush:o,deep:u,immediate:i})},e.timestamp=()=>+Date.now(),e.tryOnMounted=function(e,n=!0){t.getCurrentInstance()?t.onMounted(e):n?e():t.nextTick(e)},e.tryOnUnmounted=function(e){t.getCurrentInstance()&&t.onUnmounted(e)},e.when=function(e){let n=!1;function o(o,{flush:i="sync",timeout:r,throwOnTimeout:c}={}){let f=null;const s=[new Promise((u=>{f=t.watch(e,(e=>{o(e)===!n&&(null==f||f(),u())}),{flush:i,immediate:!0})}))];return r&&s.push(u(r,c).finally((()=>{null==f||f()}))),Promise.race(s)}function i(e,t){return o((t=>t===e),t)}function r(e=1,t){let n=-1;return o((()=>(n+=1,n>=e)),t)}return{toMatch:o,toBe:i,toBeTruthy:function(e){return o((e=>Boolean(e)),e)},toBeNull:function(e){return i(null,e)},toBeNaN:function(e){return o(Number.isNaN,e)},toBeUndefined:function(e){return i(void 0,e)},toContain:function(e,t){return o((t=>Array.from(t).includes(e)),t)},changed:function(e){return r(1,e)},changedTimes:r,get not(){return n=!n,this}}},Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("vue-demi")):"function"==typeof define&&define.amd?define(["exports","vue-demi"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self)["VueUseShared utilities"]={},e.VueDemi)}(this,(function(e,n){"use strict";const t="undefined"!=typeof window,o=Object.prototype.toString;function u(e,n=!1,t="Timeout"){return new Promise(((o,u)=>{n?setTimeout((()=>u(t)),e):setTimeout(o,e)}))}e.assert=(e,...n)=>{e||console.warn(...n)},e.biSyncRef=function(e,t){const o="sync",u=n.watch(e,(e=>{t.value=e}),{flush:o,immediate:!0}),i=n.watch(t,(n=>{e.value=n}),{flush:o,immediate:!0});return()=>{u(),i()}},e.clamp=(e,n,t)=>Math.min(t,Math.max(n,e)),e.controlledComputed=function(e,t){const o=n.ref(t());return n.watch(e,(()=>o.value=t()),{flush:"sync"}),n.computed((()=>o.value))},e.extendRef=function(e,t,{enumerable:o=!1,unwrap:u=!0}={}){for(const[i,r]of Object.entries(t))"value"!==i&&(n.isRef(r)&&u?Object.defineProperty(e,i,{get:()=>r.value,set(e){r.value=e},enumerable:o}):Object.defineProperty(e,i,{value:r,enumerable:o}));return e},e.invoke=function(e){return e()},e.isBoolean=e=>"boolean"==typeof e,e.isClient=t,e.isDef=e=>void 0!==e,e.isFunction=e=>"function"==typeof e,e.isNumber=e=>"number"==typeof e,e.isObject=e=>"[object Object]"===o.call(e),e.isString=e=>"string"==typeof e,e.isWindow=e=>"undefined"!=typeof window&&"[object Window]"===o.call(e),e.makeDestructurable=function(e,n){if("undefined"!=typeof Symbol){const t=Object.assign({},e);return Object.defineProperty(t,Symbol.iterator,{enumerable:!1,value(){let e=0;return{next:()=>({value:n[e++],done:e>n.length})}}}),t}return Object.assign([...n],e)},e.noop=()=>{},e.now=()=>Date.now(),e.promiseTimeout=u,e.syncRef=function(e,t,{flush:o="sync",deep:u=!1,immediate:i=!0}={}){return Array.isArray(t)||(t=[t]),n.watch(e,(e=>{t.forEach((n=>n.value=e))}),{flush:o,deep:u,immediate:i})},e.timestamp=()=>+Date.now(),e.tryOnMounted=function(e,t=!0){n.getCurrentInstance()?n.onMounted(e):t?e():n.nextTick(e)},e.tryOnUnmounted=function(e){n.getCurrentInstance()&&n.onUnmounted(e)},e.when=function(e){let t=!1;function o(o,{flush:i="sync",timeout:r,throwOnTimeout:c}={}){let f=null;const s=[new Promise((u=>{f=n.watch(e,(e=>{o(e)===!t&&(null==f||f(),u())}),{flush:i,immediate:!0})}))];return r&&s.push(u(r,c).finally((()=>{null==f||f()}))),Promise.race(s)}function i(e,n){return o((n=>n===e),n)}function r(e=1,n){let t=-1;return o((()=>(t+=1,t>=e)),n)}return{toMatch:o,toBe:i,toBeTruthy:function(e){return o((e=>Boolean(e)),e)},toBeNull:function(e){return i(null,e)},toBeNaN:function(e){return o(Number.isNaN,e)},toBeUndefined:function(e){return i(void 0,e)},toContain:function(e,n){return o((n=>Array.from(n).includes(e)),n)},changed:function(e){return r(1,e)},changedTimes:r,get not(){return t=!t,this}}},Object.defineProperty(e,"__esModule",{value:!0})})); |
{ | ||
"name": "@vueuse/shared", | ||
"version": "4.0.0-beta.34", | ||
"version": "4.0.0-beta.35", | ||
"main": "dist/index.cjs.js", | ||
@@ -5,0 +5,0 @@ "types": "dist/index.d.ts", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30202
815