add console.log
This commit is contained in:
parent
4569251b14
commit
0a2a0128ef
@ -3,12 +3,13 @@ import ReconnectingEventSource from "reconnecting-eventsource";
|
|||||||
import { devlog } from "../utils";
|
import { devlog } from "../utils";
|
||||||
|
|
||||||
|
|
||||||
export function useSSESubscription<T>({ enabled = true, url, onNewData, onDisconnect, marker = "" }: {
|
export function useSSESubscription<T>({ enabled = true, url, onNewData, onDisconnect, marker = "", consolelog = false }: {
|
||||||
enabled?: boolean;
|
enabled?: boolean;
|
||||||
url: string;
|
url: string;
|
||||||
onNewData: (data: T[]) => void;
|
onNewData: (data: T[]) => void;
|
||||||
onDisconnect?: () => void;
|
onDisconnect?: () => void;
|
||||||
marker?: string;
|
marker?: string;
|
||||||
|
consolelog?: boolean;
|
||||||
}) {
|
}) {
|
||||||
const onNewDataRef = useRef(onNewData);
|
const onNewDataRef = useRef(onNewData);
|
||||||
const onDisconnectRef = useRef(onDisconnect);
|
const onDisconnectRef = useRef(onDisconnect);
|
||||||
@ -27,7 +28,9 @@ export function useSSESubscription<T>({ enabled = true, url, onNewData, onDiscon
|
|||||||
eventSource.addEventListener("close", () => devlog(`EventSource closed with ${url}`));
|
eventSource.addEventListener("close", () => devlog(`EventSource closed with ${url}`));
|
||||||
eventSource.addEventListener("message", event => {
|
eventSource.addEventListener("message", event => {
|
||||||
try {
|
try {
|
||||||
|
if (consolelog) console.log(event);
|
||||||
const newData = JSON.parse(event.data) as T;
|
const newData = JSON.parse(event.data) as T;
|
||||||
|
if (newData) console.log(event.data);
|
||||||
devlog(`new SSE: ${marker}`, newData);
|
devlog(`new SSE: ${marker}`, newData);
|
||||||
onNewDataRef.current([newData]);
|
onNewDataRef.current([newData]);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@frontend/kitui",
|
"name": "@frontend/kitui",
|
||||||
"version": "2.0.1",
|
"version": "2.0.2",
|
||||||
"description": "test",
|
"description": "test",
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
"module": "./dist/index.js",
|
"module": "./dist/index.js",
|
||||||
|
Loading…
Reference in New Issue
Block a user