Skip to content

Commit

Permalink
Merge pull request #65 from arkahna/feature/annotate-functions-with-n…
Browse files Browse the repository at this point in the history
…o-this

Annotate with `this: void` to fix linting issue around unbound methods
  • Loading branch information
JakeGinnivan authored Dec 3, 2023
2 parents 9f21301 + 9384c41 commit 4de8b59
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
6 changes: 6 additions & 0 deletions .changeset/cool-schools-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@featureboard/node-sdk': minor
'@featureboard/js-sdk': minor
---

[TypeScript] Annotated SDK functions with 'this: void' to indicate the methods can be destructured without needing to be bound
9 changes: 5 additions & 4 deletions libs/js-sdk/src/client-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,24 @@ export interface BrowserClient {
*
* @throws {Error} If the initialisation process fails an error is thrown
*/
waitForInitialised(): Promise<boolean>
waitForInitialised(this: void): Promise<boolean>

/** Subscribe to initialised changes, will call back with initialised boolean value
* Recommended to be used in conjunction with updateAudiences()
*
* @returns unsubscribe function
*/
subscribeToInitialisedChanged(
this: void,
callback: (initialised: boolean) => void,
): () => void

/** Will set initialised to false until the new audiences are loaded */
updateAudiences(audiences: string[]): PromiseLike<void>
updateAudiences(this: void, audiences: string[]): PromiseLike<void>

/** Manually triggers an update to the feature state */
updateFeatures(): PromiseLike<void>
updateFeatures(this: void): PromiseLike<void>

/** Closes subscription to the FeatureBoard service */
close: () => void
close: (this: void) => void
}
4 changes: 3 additions & 1 deletion libs/js-sdk/src/features-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { FeatureBoardEffectiveStateJS } from './js-state'

export interface FeatureBoardClient {
getFeatureValue<T extends keyof Features>(
this: void,
featureKey: T,
defaultValue: Features[T],
): Features[T]
Expand All @@ -13,10 +14,11 @@ export interface FeatureBoardClient {
* @returns unsubscribe function
*/
subscribeToFeatureValue<T extends keyof Features>(
this: void,
featureKey: keyof Features,
defaultValue: Features[T],
onValue: (value: Features[T]) => void,
): () => void

getEffectiveValues(): FeatureBoardEffectiveStateJS
getEffectiveValues(this: void): FeatureBoardEffectiveStateJS
}
7 changes: 4 additions & 3 deletions libs/node-sdk/src/server-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface ServerClient {
* immediately call back with the current value and will not subscribe to the feature in the state store.
**/
request(
this: void,
audiences: string[],
): FeatureBoardClient & PromiseLike<FeatureBoardClient>

Expand All @@ -22,10 +23,10 @@ export interface ServerClient {
*
* @throws {Error} If the initialisation process fails an error is thrown
*/
waitForInitialised(): Promise<boolean>
waitForInitialised(this: void): Promise<boolean>

/** Manually triggers an update to the feature state */
updateFeatures(): PromiseLike<void>
updateFeatures(this: void): PromiseLike<void>

close(): void
close(this: void): void
}

0 comments on commit 4de8b59

Please sign in to comment.