reshow-hooks
Advanced tools
Comparing version 0.17.34 to 0.17.35
@@ -30,5 +30,9 @@ "use strict"; | ||
timerRun = _useTimer[0], | ||
timerStop = _useTimer[1]; | ||
timerStop = _useTimer[1], | ||
timerIsRunning = _useTimer[2]; | ||
return (0, _react.useMemo)(function () { | ||
var start = function start( /**@type React.MouseEvent*/e) { | ||
if (timerIsRunning()) { | ||
return; | ||
} | ||
var currentTarget = e === null || e === void 0 ? void 0 : e.currentTarget; | ||
@@ -45,2 +49,5 @@ var _lastPayload$current = lastPayload.current, | ||
var cancel = function cancel( /**@type React.MouseEvent*/e) { | ||
if (!timerIsRunning()) { | ||
return; | ||
} | ||
var currentTarget = e === null || e === void 0 ? void 0 : e.currentTarget; | ||
@@ -53,5 +60,11 @@ timerStop(); | ||
onMouseDown: start, | ||
onMouseUp: cancel | ||
onMouseUp: cancel, | ||
onMouseLeave: cancel | ||
}; | ||
return mouseHandlers; | ||
var touchHandlers = { | ||
onTouchStart: start, | ||
onTouchEnd: cancel, | ||
onTouchMove: cancel | ||
}; | ||
return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, mouseHandlers), touchHandlers); | ||
}, [callback]); | ||
@@ -58,0 +71,0 @@ }; |
@@ -12,4 +12,9 @@ "use strict"; | ||
/** | ||
* @callback RunType | ||
* @param {function} func | ||
* @param {number} delay | ||
*/ | ||
/** | ||
* @param {boolean} [interval] | ||
* @returns {[Function, Function]} | ||
* @returns {[RunType, function, function():boolean]} | ||
*/ | ||
@@ -40,4 +45,3 @@ var useTimer = function useTimer(interval) { | ||
/** | ||
* @param {function} func | ||
* @param {number} [delay] | ||
* @type RunType | ||
*/ | ||
@@ -48,3 +52,6 @@ var run = function run(func, delay) { | ||
}; | ||
return [run, stop]; | ||
var isRunning = function isRunning() { | ||
return !!timer.current; | ||
}; | ||
return [run, stop, isRunning]; | ||
}; | ||
@@ -51,0 +58,0 @@ var _default = useTimer; |
{ | ||
"version": "0.17.34", | ||
"version": "0.17.35", | ||
"name": "reshow-hooks", | ||
@@ -4,0 +4,0 @@ "repository": { |
@@ -18,4 +18,8 @@ export default useLongPress; | ||
declare function useLongPress(callback: Function, payload?: LongPressPayload): { | ||
onTouchStart: (e: React.MouseEvent) => void; | ||
onTouchEnd: (e: React.MouseEvent) => void; | ||
onTouchMove: (e: React.MouseEvent) => void; | ||
onMouseDown: (e: React.MouseEvent) => void; | ||
onMouseUp: (e: React.MouseEvent) => void; | ||
onMouseLeave: (e: React.MouseEvent) => void; | ||
}; |
export default useTimer; | ||
export type RunType = (func: Function, delay: number) => any; | ||
/** | ||
* @callback RunType | ||
* @param {function} func | ||
* @param {number} delay | ||
*/ | ||
/** | ||
* @param {boolean} [interval] | ||
* @returns {[Function, Function]} | ||
* @returns {[RunType, function, function():boolean]} | ||
*/ | ||
declare function useTimer(interval?: boolean): [Function, Function]; | ||
declare function useTimer(interval?: boolean): [RunType, Function, () => boolean]; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
33467
987