@vueuse/core
Advanced tools
Comparing version 3.0.0-alpha.5 to 3.0.0-alpha.7
@@ -7,1 +7,3 @@ export { init } from './api'; | ||
export * from './useTimeoutFn'; | ||
export * from './useIntervalFn'; | ||
export * from './useWindowSize'; |
@@ -13,2 +13,4 @@ "use strict"; | ||
__export(require("./useTimeoutFn")); | ||
__export(require("./useIntervalFn")); | ||
__export(require("./useWindowSize")); | ||
//# sourceMappingURL=index.js.map |
@@ -1,1 +0,5 @@ | ||
export declare function useTimeout(ms?: number): readonly [import("@vue/reactivity").Ref<boolean>, () => void, () => void]; | ||
export declare function useTimeout(interval?: number, startRightNow?: boolean): { | ||
readonly ready: import("@vue/reactivity").Ref<boolean>; | ||
readonly start: () => void; | ||
readonly stop: () => void; | ||
}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var api_1 = require("../api"); | ||
function useTimeout(ms) { | ||
if (ms === void 0) { ms = 1000; } | ||
function useTimeout(interval, startRightNow) { | ||
if (interval === void 0) { interval = 1000; } | ||
if (startRightNow === void 0) { startRightNow = true; } | ||
var ready = api_1.ref(false); | ||
var timer = null; | ||
function clear() { | ||
function stop() { | ||
ready.value = false; | ||
if (timer) { | ||
ready.value = false; | ||
clearTimeout(timer); | ||
@@ -16,17 +17,15 @@ timer = null; | ||
function start() { | ||
clear(); | ||
stop(); | ||
timer = setTimeout(function () { | ||
ready.value = true; | ||
}, ms); | ||
timer = null; | ||
}, interval); | ||
} | ||
start(); | ||
if (startRightNow) | ||
start(); | ||
if (api_1.getCurrentInstance()) | ||
api_1.onUnmounted(clear); | ||
return [ | ||
ready, | ||
clear, | ||
start, | ||
]; | ||
api_1.onUnmounted(stop); | ||
return { ready: ready, start: start, stop: stop }; | ||
} | ||
exports.useTimeout = useTimeout; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,5 @@ | ||
import { Ref } from '../api'; | ||
export declare function useTimeoutFn(cb: () => any, ms?: number): [() => any, () => any, Ref<boolean>]; | ||
export declare function useTimeoutFn(cb: () => any, interval?: number): { | ||
ready: import("@vue/reactivity").Ref<boolean>; | ||
start: () => void; | ||
stop: () => void; | ||
}; |
@@ -5,10 +5,10 @@ "use strict"; | ||
var __1 = require(".."); | ||
function useTimeoutFn(cb, ms) { | ||
var _a = __1.useTimeout(ms), ready = _a[0], clear = _a[1], runAgain = _a[2]; | ||
function useTimeoutFn(cb, interval) { | ||
var _a = __1.useTimeout(interval), ready = _a.ready, start = _a.start, stop = _a.stop; | ||
api_1.watch(ready, function (maturity) { | ||
maturity && cb(); | ||
}, { lazy: true }); | ||
return [clear, runAgain, ready]; | ||
return { ready: ready, start: start, stop: stop }; | ||
} | ||
exports.useTimeoutFn = useTimeoutFn; | ||
//# sourceMappingURL=index.js.map |
@@ -7,1 +7,3 @@ export { init } from './api'; | ||
export * from './useTimeoutFn'; | ||
export * from './useIntervalFn'; | ||
export * from './useWindowSize'; |
@@ -7,2 +7,4 @@ export { init } from './api'; | ||
export * from './useTimeoutFn'; | ||
export * from './useIntervalFn'; | ||
export * from './useWindowSize'; | ||
//# sourceMappingURL=index.js.map |
@@ -1,1 +0,5 @@ | ||
export declare function useTimeout(ms?: number): readonly [import("@vue/reactivity").Ref<boolean>, () => void, () => void]; | ||
export declare function useTimeout(interval?: number, startRightNow?: boolean): { | ||
readonly ready: import("@vue/reactivity").Ref<boolean>; | ||
readonly start: () => void; | ||
readonly stop: () => void; | ||
}; |
import { ref, onUnmounted, getCurrentInstance } from '../api'; | ||
export function useTimeout(ms) { | ||
if (ms === void 0) { ms = 1000; } | ||
export function useTimeout(interval, startRightNow) { | ||
if (interval === void 0) { interval = 1000; } | ||
if (startRightNow === void 0) { startRightNow = true; } | ||
var ready = ref(false); | ||
var timer = null; | ||
function clear() { | ||
function stop() { | ||
ready.value = false; | ||
if (timer) { | ||
ready.value = false; | ||
clearTimeout(timer); | ||
@@ -14,16 +15,14 @@ timer = null; | ||
function start() { | ||
clear(); | ||
stop(); | ||
timer = setTimeout(function () { | ||
ready.value = true; | ||
}, ms); | ||
timer = null; | ||
}, interval); | ||
} | ||
start(); | ||
if (startRightNow) | ||
start(); | ||
if (getCurrentInstance()) | ||
onUnmounted(clear); | ||
return [ | ||
ready, | ||
clear, | ||
start, | ||
]; | ||
onUnmounted(stop); | ||
return { ready: ready, start: start, stop: stop }; | ||
} | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,5 @@ | ||
import { Ref } from '../api'; | ||
export declare function useTimeoutFn(cb: () => any, ms?: number): [() => any, () => any, Ref<boolean>]; | ||
export declare function useTimeoutFn(cb: () => any, interval?: number): { | ||
ready: import("@vue/reactivity").Ref<boolean>; | ||
start: () => void; | ||
stop: () => void; | ||
}; |
import { watch } from '../api'; | ||
import { useTimeout } from '..'; | ||
export function useTimeoutFn(cb, ms) { | ||
var _a = useTimeout(ms), ready = _a[0], clear = _a[1], runAgain = _a[2]; | ||
export function useTimeoutFn(cb, interval) { | ||
var _a = useTimeout(interval), ready = _a.ready, start = _a.start, stop = _a.stop; | ||
watch(ready, function (maturity) { | ||
maturity && cb(); | ||
}, { lazy: true }); | ||
return [clear, runAgain, ready]; | ||
return { ready: ready, start: start, stop: stop }; | ||
} | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@vueuse/core", | ||
"version": "3.0.0-alpha.5", | ||
"version": "3.0.0-alpha.7", | ||
"description": "Collection of essential Vue Composition API", | ||
@@ -66,2 +66,3 @@ "main": "dist/main/index.js", | ||
"commander": "^4.0.1", | ||
"consola": "^2.11.1", | ||
"eslint": "6.8.0", | ||
@@ -68,0 +69,0 @@ "eslint-plugin-jest": "23.1.1", |
<p align="center"> | ||
<img src="./screenshots/logo.png" alt="logo" width="300"/> | ||
<img src="https://github.com/antfu/vueuse/blob/master/screenshots/logo.png?raw=true" alt="logo" width="300"/> | ||
</p> | ||
@@ -23,3 +23,3 @@ | ||
### Vue 3.x ([vue-next](https://github.com/vuejs/vue-next)) | ||
### for Vue 3.x ([vue-next](https://github.com/vuejs/vue-next)) | ||
@@ -30,3 +30,3 @@ ```bash | ||
### Vue 2.x with [composition-api](https://github.com/vuejs/composition-api) polyfill | ||
### for Vue 2.x with [composition-api](https://github.com/vuejs/composition-api) polyfill | ||
@@ -36,6 +36,6 @@ | ||
npm i @vue/composition-api | ||
npm i @vueuse/core@2 | ||
npm i @vueuse/core | ||
``` | ||
[Register the Composition API Plugin](https://github.com/vuejs/composition-api#usage) before other APIs. | ||
Please [register the Composition API Plugin](https://github.com/vuejs/composition-api#usage) before other using APIs. | ||
@@ -52,3 +52,3 @@ ## ⚡ Functions | ||
More functions to be added. Please keep turned. | ||
More functions to be added. Please keep turned. (PRs are also welcome!) | ||
@@ -55,0 +55,0 @@ ## 📄 License |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
35697
63
465
47