@rpldy/shared-ui
Advanced tools
Comparing version 0.2.2 to 0.2.3
@@ -18,3 +18,3 @@ "use strict"; | ||
var useBatchAddListener = (0, _utils.generateUploaderEventHook)(_uploader.UPLOADER_EVENTS.BATCH_ADD); | ||
var useBatchAddListener = (0, _utils.generateUploaderEventHook)(_uploader.UPLOADER_EVENTS.BATCH_ADD, false); | ||
exports.useBatchAddListener = useBatchAddListener; | ||
@@ -49,3 +49,3 @@ var useBatchStartListener = (0, _utils.generateUploaderEventHook)(_uploader.UPLOADER_EVENTS.BATCH_START); | ||
exports.useItemProgressListener = useItemProgressListener; | ||
var useRequestPreSend = (0, _utils.generateUploaderEventHook)(_uploader.UPLOADER_EVENTS.REQUEST_PRE_SEND); | ||
var useRequestPreSend = (0, _utils.generateUploaderEventHook)(_uploader.UPLOADER_EVENTS.REQUEST_PRE_SEND, false); | ||
exports.useRequestPreSend = useRequestPreSend; |
@@ -37,3 +37,3 @@ "use strict"; | ||
var generateUploaderEventHookWithState = function generateUploaderEventHookWithState(event, stateCalculator) { | ||
return function (fn) { | ||
return function (fn, id) { | ||
var _useState = (0, _react.useState)(null), | ||
@@ -44,9 +44,15 @@ _useState2 = _slicedToArray(_useState, 2), | ||
var eventCallback = (0, _react.useCallback)(function () { | ||
setEventState(stateCalculator.apply(void 0, arguments)); | ||
var eventCallback = (0, _react.useCallback)(function (eventObj) { | ||
if (!id || eventObj.id === id) { | ||
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
args[_key - 1] = arguments[_key]; | ||
} | ||
if (fn) { | ||
fn.apply(void 0, arguments); | ||
setEventState(stateCalculator.apply(void 0, [eventObj].concat(args))); | ||
if (fn) { | ||
fn.apply(void 0, [eventObj].concat(args)); | ||
} | ||
} | ||
}, [fn]); | ||
}, [fn, id]); | ||
useEventEffect(event, eventCallback); | ||
@@ -60,4 +66,12 @@ return eventState; | ||
var generateUploaderEventHook = function generateUploaderEventHook(event) { | ||
return function (fn) { | ||
return useEventEffect(event, fn); | ||
var canScope = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; | ||
return function (fn, id) { | ||
var eventCallback = (0, _react.useCallback)(function (eventObj) { | ||
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
args[_key2 - 1] = arguments[_key2]; | ||
} | ||
return fn && (!canScope || !id || eventObj.id === id) ? fn.apply(void 0, [eventObj].concat(args)) : undefined; | ||
}, [fn, id]); | ||
useEventEffect(event, eventCallback); | ||
}; | ||
@@ -64,0 +78,0 @@ }; |
{ | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"name": "@rpldy/shared-ui", | ||
@@ -20,4 +20,4 @@ "description": "internal set of utils+types for react-uploady UI", | ||
"dependencies": { | ||
"@rpldy/shared": "^0.2.0", | ||
"@rpldy/uploader": "^0.2.2" | ||
"@rpldy/shared": "^0.2.3", | ||
"@rpldy/uploader": "^0.2.3" | ||
}, | ||
@@ -34,3 +34,3 @@ "devDependencies": { | ||
}, | ||
"gitHead": "e0a9cc52ebf62f90471844208472d660f3e0e7cd" | ||
"gitHead": "ae30dff0980d764282621e8fbead581ba4f1386b" | ||
} |
@@ -26,5 +26,5 @@ import * as React from "react"; | ||
type EventHook<T> = (cb: (obj: T) => void) => void; | ||
type CancellableHook<T> = (cb: (obj: T) => boolean | void) => void; | ||
type EventHookWithState<T> = (cb?: (obj: T) => void) => T; | ||
type EventHook<T> = (cb: (obj: T) => void, id?: string) => void; | ||
type CancellableHook<T> = (cb: (obj: T) => boolean | void, id?: string) => void; | ||
type EventHookWithState<T> = (cb?: (obj: T) => void, id?: string) => T; | ||
@@ -31,0 +31,0 @@ type ItemEventHook = EventHook<BatchItem>; |
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
42197
656
Updated@rpldy/shared@^0.2.3
Updated@rpldy/uploader@^0.2.3