Skip to content

Commit 040d6ed

Browse files
committed
feat: improve event listeners, expose more types
1 parent 16e1f35 commit 040d6ed

4 files changed

Lines changed: 13 additions & 4 deletions

File tree

packages/browser-sdk/src/client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,7 @@ export class BucketClient {
482482
handler: (args0: HookArgs[THookType]) => void,
483483
) {
484484
this.hooks.addHook(type, handler);
485+
return () => this.hooks.removeHook(type, handler);
485486
}
486487

487488
/**

packages/browser-sdk/src/hooksManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export interface HookArgs {
1313
track: TrackEvent;
1414
}
1515

16-
type TrackEvent = {
16+
export type TrackEvent = {
1717
user: UserContext;
1818
company?: CompanyContext;
1919
eventName: string;

packages/browser-sdk/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export type { Feature, InitOptions, ToolbarOptions } from "./client";
22
export { BucketClient } from "./client";
33
export type { BucketContext, CompanyContext, UserContext } from "./context";
4+
export type { TrackEvent } from "./hooksManager";
45
export type {
56
CheckEvent,
67
FallbackFeatureOverride,

packages/react-sdk/src/index.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@ import {
1717
RawFeatures,
1818
RequestFeedbackData,
1919
UnassignedFeedback,
20+
TrackEvent,
21+
UserContext,
22+
CompanyContext,
23+
CheckEvent,
2024
} from "@bucketco/browser-sdk";
2125

26+
export { TrackEvent, UserContext, CompanyContext, CheckEvent, RawFeatures };
2227
import { version } from "../package.json";
2328

2429
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
@@ -349,9 +354,11 @@ export function useUpdateOtherContext() {
349354
*
350355
* ```ts
351356
* const client = useClient();
352-
* client.on("configCheck", () => {
353-
* console.log("configCheck hook called");
354-
* });
357+
* useEffect(() => {
358+
* return client?.on("enabledCheck", () => {
359+
* console.log("enabledCheck hook called");
360+
* });
361+
* }, [client]);
355362
* ```
356363
*/
357364
export function useClient() {

0 commit comments

Comments
 (0)