Skip to content

Commit a05e94d

Browse files
committed
checkIsEnabled -> isEnabledCheck etc.
1 parent 28c7a13 commit a05e94d

File tree

7 files changed

+28
-34
lines changed

7 files changed

+28
-34
lines changed

packages/browser-sdk/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ const client = new BucketClient({
328328
});
329329

330330
// or add the hooks after construction:
331-
const unsub = client.on("checkIsEnabled", (check: CheckEvent) =>
331+
const unsub = client.on("isEnabledCheck", (check: CheckEvent) =>
332332
console.log(`Check event ${check}`),
333333
);
334334
// use the returned function to unsubscribe, or call `off()` with the same arguments again

packages/browser-sdk/example/typescript/app.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@ const bucket = new BucketClient({
1616
show: true,
1717
position: { placement: "bottom-right" },
1818
},
19-
hooks: [
20-
{
21-
type: "checkIsEnabled",
22-
handler: (check: CheckEvent) => console.log("Check event for", check.key),
23-
},
24-
],
2519
});
2620

2721
document

packages/browser-sdk/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
document.getElementById("loading").style.display = "none";
5555
});
5656

57-
bucket.on("checkIsEnabled", (check) =>
57+
bucket.on("isEnabledCheck", (check) =>
5858
console.log(`Check event for ${check.key}`),
5959
);
6060

packages/browser-sdk/src/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ export class BucketClient {
781781
sendCheckEvent(checkEvent: CheckEvent) {
782782
return this.featuresClient.sendCheckEvent(checkEvent, () => {
783783
this.hooks.trigger(
784-
checkEvent.action == "check-config" ? "checkConfig" : "checkIsEnabled",
784+
checkEvent.action == "check-config" ? "configCheck" : "isEnabledCheck",
785785
checkEvent,
786786
);
787787
});

packages/browser-sdk/src/hooksManager.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { CompanyContext, UserContext } from "./context";
55
* @internal
66
*/
77
export interface HookArgs {
8-
checkConfig: CheckEvent;
9-
checkIsEnabled: CheckEvent;
8+
configCheck: CheckEvent;
9+
isEnabledCheck: CheckEvent;
1010
featuresUpdated: RawFeatures;
1111
user: UserContext;
1212
company: CompanyContext;
@@ -26,15 +26,15 @@ type TrackEvent = {
2626
*/
2727
export class HooksManager {
2828
private hooks: {
29-
checkIsEnabled: ((arg0: CheckEvent) => void)[];
30-
checkConfig: ((arg0: CheckEvent) => void)[];
29+
isEnabledCheck: ((arg0: CheckEvent) => void)[];
30+
configCheck: ((arg0: CheckEvent) => void)[];
3131
featuresUpdated: ((arg0: RawFeatures) => void)[];
3232
user: ((arg0: UserContext) => void)[];
3333
company: ((arg0: CompanyContext) => void)[];
3434
track: ((arg0: TrackEvent) => void)[];
3535
} = {
36-
checkIsEnabled: [],
37-
checkConfig: [],
36+
isEnabledCheck: [],
37+
configCheck: [],
3838
featuresUpdated: [],
3939
user: [],
4040
company: [],

packages/browser-sdk/test/client.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ describe("BucketClient", () => {
8787
client.on("track", trackHook);
8888
client.on("user", userHook);
8989
client.on("company", companyHook);
90-
client.on("checkConfig", checkHookConfig);
91-
client.on("checkIsEnabled", checkHookIsEnabled);
90+
client.on("configCheck", checkHookConfig);
91+
client.on("isEnabledCheck", checkHookIsEnabled);
9292
client.on("featuresUpdated", featuresUpdated);
9393

9494
await client.track("test-event");
@@ -119,8 +119,8 @@ describe("BucketClient", () => {
119119
client.off("track", trackHook);
120120
client.off("user", userHook);
121121
client.off("company", companyHook);
122-
client.off("checkConfig", checkHookConfig);
123-
client.off("checkIsEnabled", checkHookIsEnabled);
122+
client.off("configCheck", checkHookConfig);
123+
client.off("isEnabledCheck", checkHookIsEnabled);
124124
client.off("featuresUpdated", featuresUpdated);
125125

126126
// Reset mocks

packages/browser-sdk/test/hooksManager.test.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,28 @@ describe("HookManager", () => {
1313

1414
it("should add and trigger check-is-enabled hooks", () => {
1515
const callback = vi.fn();
16-
hookManager.addHook("checkIsEnabled", callback);
16+
hookManager.addHook("isEnabledCheck", callback);
1717

1818
const checkEvent: CheckEvent = {
1919
action: "check-is-enabled",
2020
key: "test-key",
2121
value: true,
2222
};
23-
hookManager.trigger("checkIsEnabled", checkEvent);
23+
hookManager.trigger("isEnabledCheck", checkEvent);
2424

2525
expect(callback).toHaveBeenCalledWith(checkEvent);
2626
});
2727

28-
it("should add and trigger checkConfig hooks", () => {
28+
it("should add and trigger configCheck hooks", () => {
2929
const callback = vi.fn();
30-
hookManager.addHook("checkConfig", callback);
30+
hookManager.addHook("configCheck", callback);
3131

3232
const checkEvent: CheckEvent = {
3333
action: "check-config",
3434
key: "test-key",
3535
value: { key: "key", payload: "payload" },
3636
};
37-
hookManager.trigger("checkConfig", checkEvent);
37+
hookManager.trigger("configCheck", checkEvent);
3838

3939
expect(callback).toHaveBeenCalledWith(checkEvent);
4040
});
@@ -94,15 +94,15 @@ describe("HookManager", () => {
9494
const callback1 = vi.fn();
9595
const callback2 = vi.fn();
9696

97-
hookManager.addHook("checkIsEnabled", callback1);
98-
hookManager.addHook("checkIsEnabled", callback2);
97+
hookManager.addHook("isEnabledCheck", callback1);
98+
hookManager.addHook("isEnabledCheck", callback2);
9999

100100
const checkEvent: CheckEvent = {
101101
action: "check-is-enabled",
102102
key: "test-key",
103103
value: true,
104104
};
105-
hookManager.trigger("checkIsEnabled", checkEvent);
105+
hookManager.trigger("isEnabledCheck", checkEvent);
106106

107107
expect(callback1).toHaveBeenCalledWith(checkEvent);
108108
expect(callback2).toHaveBeenCalledWith(checkEvent);
@@ -112,16 +112,16 @@ describe("HookManager", () => {
112112
const callback1 = vi.fn();
113113
const callback2 = vi.fn();
114114

115-
hookManager.addHook("checkIsEnabled", callback1);
116-
hookManager.addHook("checkIsEnabled", callback2);
117-
hookManager.removeHook("checkIsEnabled", callback1);
115+
hookManager.addHook("isEnabledCheck", callback1);
116+
hookManager.addHook("isEnabledCheck", callback2);
117+
hookManager.removeHook("isEnabledCheck", callback1);
118118

119119
const checkEvent: CheckEvent = {
120120
action: "check-is-enabled",
121121
key: "test-key",
122122
value: true,
123123
};
124-
hookManager.trigger("checkIsEnabled", checkEvent);
124+
hookManager.trigger("isEnabledCheck", checkEvent);
125125

126126
expect(callback1).not.toHaveBeenCalled();
127127
expect(callback2).toHaveBeenCalledWith(checkEvent);
@@ -131,16 +131,16 @@ describe("HookManager", () => {
131131
const callback1 = vi.fn();
132132
const callback2 = vi.fn();
133133

134-
const removeHook1 = hookManager.addHook("checkIsEnabled", callback1);
135-
hookManager.addHook("checkIsEnabled", callback2);
134+
const removeHook1 = hookManager.addHook("isEnabledCheck", callback1);
135+
hookManager.addHook("isEnabledCheck", callback2);
136136
removeHook1();
137137

138138
const checkEvent: CheckEvent = {
139139
action: "check-is-enabled",
140140
key: "test-key",
141141
value: true,
142142
};
143-
hookManager.trigger("checkIsEnabled", checkEvent);
143+
hookManager.trigger("isEnabledCheck", checkEvent);
144144

145145
expect(callback1).not.toHaveBeenCalled();
146146
expect(callback2).toHaveBeenCalledWith(checkEvent);

0 commit comments

Comments
 (0)