@trackunit/react-core-hooks
Advanced tools
Comparing version 0.2.228 to 0.2.229
@@ -50,4 +50,26 @@ 'use strict'; | ||
} | ||
return context; | ||
const logEvent = React.useMemo(() => logEventWithDescription(context.logEvent, events), [context.logEvent, events]); | ||
return { | ||
...context, | ||
logEvent, | ||
}; | ||
}; | ||
// Automatically append the description from the event type | ||
const logEventWithDescription = (logEvent, events) => { | ||
return (eventName, details, nameSupplement) => { | ||
const event = events === null || events === void 0 ? void 0 : events[eventName]; | ||
const eventDescription = event === null || event === void 0 ? void 0 : event.description; | ||
// Include description in the details object. | ||
const detailsWithDescription = { | ||
eventDescription, | ||
...details, | ||
}; | ||
if (nameSupplement) { | ||
logEvent(eventName, detailsWithDescription, nameSupplement); | ||
} | ||
else { | ||
logEvent(eventName, detailsWithDescription); | ||
} | ||
}; | ||
}; | ||
@@ -54,0 +76,0 @@ const AssetSortingContext = React.createContext(null); |
import * as React from 'react'; | ||
import { createContext, useContext, useState, useCallback, useMemo, useEffect } from 'react'; | ||
import { createContext, useContext, useMemo, useState, useCallback, useEffect } from 'react'; | ||
import { jsx } from 'react/jsx-runtime'; | ||
@@ -30,4 +30,26 @@ import { AssetRuntime, CustomerRuntime, EventRuntime, ParamsRuntime, SiteRuntime } from '@trackunit/iris-app-runtime-core'; | ||
} | ||
return context; | ||
const logEvent = useMemo(() => logEventWithDescription(context.logEvent, events), [context.logEvent, events]); | ||
return { | ||
...context, | ||
logEvent, | ||
}; | ||
}; | ||
// Automatically append the description from the event type | ||
const logEventWithDescription = (logEvent, events) => { | ||
return (eventName, details, nameSupplement) => { | ||
const event = events === null || events === void 0 ? void 0 : events[eventName]; | ||
const eventDescription = event === null || event === void 0 ? void 0 : event.description; | ||
// Include description in the details object. | ||
const detailsWithDescription = { | ||
eventDescription, | ||
...details, | ||
}; | ||
if (nameSupplement) { | ||
logEvent(eventName, detailsWithDescription, nameSupplement); | ||
} | ||
else { | ||
logEvent(eventName, detailsWithDescription); | ||
} | ||
}; | ||
}; | ||
@@ -34,0 +56,0 @@ const AssetSortingContext = createContext(null); |
{ | ||
"name": "@trackunit/react-core-hooks", | ||
"version": "0.2.228", | ||
"version": "0.2.229", | ||
"repository": "https://github.com/Trackunit/manager", | ||
@@ -5,0 +5,0 @@ "license": "SEE LICENSE IN LICENSE.txt", |
@@ -1,2 +0,2 @@ | ||
import { BaseEvent, Event, IAnalyticsContext, UnspecifiedEvent } from "@trackunit/react-core-contexts-api"; | ||
import { EventDictionary, IAnalyticsContext } from "@trackunit/react-core-contexts-api"; | ||
export declare const AnalyticsContext: import("react").Context<IAnalyticsContext<Record<string, never>> | null>; | ||
@@ -20,2 +20,2 @@ export declare const AnalyticsContextProvider: import("react").Provider<IAnalyticsContext<Record<string, never>> | null>; | ||
*/ | ||
export declare const useAnalytics: <TEvents extends Record<string, Event<BaseEvent | UnspecifiedEvent>> = never>(events: TEvents) => IAnalyticsContext<TEvents>; | ||
export declare const useAnalytics: <TEvents extends EventDictionary = never>(events: TEvents) => IAnalyticsContext<TEvents>; |
83282
2333