@reactuses/core 6.0.1 → 6.0.3-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +11 -6
- package/dist/index.mjs +11 -6
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -48,8 +48,8 @@ function off(obj, ...args) {
|
|
|
48
48
|
obj.removeEventListener(...args);
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
-
const defaultWindow =
|
|
52
|
-
const defaultDocument =
|
|
51
|
+
const defaultWindow = typeof window !== 'undefined' ? window : undefined;
|
|
52
|
+
const defaultDocument = typeof document !== 'undefined' ? document : undefined;
|
|
53
53
|
|
|
54
54
|
const defaultOptions$1 = {};
|
|
55
55
|
function defaultOnError(e) {
|
|
@@ -3469,19 +3469,24 @@ const useEventSource = (url, events = [], options = defaultOptions$1)=>{
|
|
|
3469
3469
|
}
|
|
3470
3470
|
});
|
|
3471
3471
|
});
|
|
3472
|
-
const close = React.useCallback(()=>{
|
|
3472
|
+
const close = React.useCallback((explicit = false)=>{
|
|
3473
3473
|
var _eventSourceRef_current;
|
|
3474
3474
|
setStatus('DISCONNECTED');
|
|
3475
3475
|
clean();
|
|
3476
3476
|
(_eventSourceRef_current = eventSourceRef.current) == null ? void 0 : _eventSourceRef_current.close();
|
|
3477
3477
|
eventSourceRef.current = null;
|
|
3478
|
-
explicitlyClosed.current =
|
|
3478
|
+
explicitlyClosed.current = explicit;
|
|
3479
3479
|
}, [
|
|
3480
3480
|
clean
|
|
3481
3481
|
]);
|
|
3482
|
+
const explicitlyClose = React.useCallback(()=>{
|
|
3483
|
+
close(true);
|
|
3484
|
+
}, [
|
|
3485
|
+
close
|
|
3486
|
+
]);
|
|
3482
3487
|
const open = useEvent(()=>{
|
|
3483
3488
|
close();
|
|
3484
|
-
|
|
3489
|
+
setStatus('CONNECTING');
|
|
3485
3490
|
retries.current = 0;
|
|
3486
3491
|
if (!eventSourceRef.current) {
|
|
3487
3492
|
eventSourceRef.current = new EventSource(url, {
|
|
@@ -3542,7 +3547,7 @@ const useEventSource = (url, events = [], options = defaultOptions$1)=>{
|
|
|
3542
3547
|
status,
|
|
3543
3548
|
lastEventId,
|
|
3544
3549
|
event,
|
|
3545
|
-
close,
|
|
3550
|
+
close: explicitlyClose,
|
|
3546
3551
|
open
|
|
3547
3552
|
};
|
|
3548
3553
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -40,8 +40,8 @@ function off(obj, ...args) {
|
|
|
40
40
|
obj.removeEventListener(...args);
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
-
const defaultWindow =
|
|
44
|
-
const defaultDocument =
|
|
43
|
+
const defaultWindow = typeof window !== 'undefined' ? window : undefined;
|
|
44
|
+
const defaultDocument = typeof document !== 'undefined' ? document : undefined;
|
|
45
45
|
|
|
46
46
|
const defaultOptions$1 = {};
|
|
47
47
|
function defaultOnError(e) {
|
|
@@ -3461,19 +3461,24 @@ const useEventSource = (url, events = [], options = defaultOptions$1)=>{
|
|
|
3461
3461
|
}
|
|
3462
3462
|
});
|
|
3463
3463
|
});
|
|
3464
|
-
const close = useCallback(()=>{
|
|
3464
|
+
const close = useCallback((explicit = false)=>{
|
|
3465
3465
|
var _eventSourceRef_current;
|
|
3466
3466
|
setStatus('DISCONNECTED');
|
|
3467
3467
|
clean();
|
|
3468
3468
|
(_eventSourceRef_current = eventSourceRef.current) == null ? void 0 : _eventSourceRef_current.close();
|
|
3469
3469
|
eventSourceRef.current = null;
|
|
3470
|
-
explicitlyClosed.current =
|
|
3470
|
+
explicitlyClosed.current = explicit;
|
|
3471
3471
|
}, [
|
|
3472
3472
|
clean
|
|
3473
3473
|
]);
|
|
3474
|
+
const explicitlyClose = useCallback(()=>{
|
|
3475
|
+
close(true);
|
|
3476
|
+
}, [
|
|
3477
|
+
close
|
|
3478
|
+
]);
|
|
3474
3479
|
const open = useEvent(()=>{
|
|
3475
3480
|
close();
|
|
3476
|
-
|
|
3481
|
+
setStatus('CONNECTING');
|
|
3477
3482
|
retries.current = 0;
|
|
3478
3483
|
if (!eventSourceRef.current) {
|
|
3479
3484
|
eventSourceRef.current = new EventSource(url, {
|
|
@@ -3534,7 +3539,7 @@ const useEventSource = (url, events = [], options = defaultOptions$1)=>{
|
|
|
3534
3539
|
status,
|
|
3535
3540
|
lastEventId,
|
|
3536
3541
|
event,
|
|
3537
|
-
close,
|
|
3542
|
+
close: explicitlyClose,
|
|
3538
3543
|
open
|
|
3539
3544
|
};
|
|
3540
3545
|
};
|