Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: move initialization into class methods, limit singleton use #170

Merged
merged 12 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/js-client-sdk.eppojsclient.instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

## EppoJSClient.instance property

@<!-- -->deprecated. use `getInstance()` instead.

**Signature:**

```typescript
Expand Down
2 changes: 2 additions & 0 deletions docs/js-client-sdk.eppojsclient.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ boolean

</td><td>

@<!-- -->deprecated. use `getInstance()` instead.


</td></tr>
</tbody></table>
Expand Down
4 changes: 2 additions & 2 deletions docs/js-client-sdk.getinstance.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ Used to access a singleton SDK client instance. Use the method after calling ini
**Signature:**

```typescript
export declare function getInstance(): EppoClient;
export declare function getInstance(): EppoJSClient;
```
**Returns:**

EppoClient
[EppoJSClient](./js-client-sdk.eppojsclient.md)

a singleton client instance

6 changes: 3 additions & 3 deletions docs/js-client-sdk.init.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

## init() function

Initializes the Eppo client with configuration parameters. This method should be called once on application startup. If an initialization is in process, calling `init` will return the in-progress `Promise<EppoClient>`<!-- -->. Once the initialization completes, calling `init` again will kick off the initialization routine (if `forceReinitialization` is `true`<!-- -->).
Initializes the Eppo client with configuration parameters. This method should be called once on application startup.

**Signature:**

```typescript
export declare function init(config: IClientConfig): Promise<EppoClient>;
export declare function init(config: IClientConfig): Promise<EppoJSClient>;
```

## Parameters
Expand Down Expand Up @@ -49,5 +49,5 @@ client configuration
</tbody></table>
**Returns:**

Promise&lt;EppoClient&gt;
Promise&lt;[EppoJSClient](./js-client-sdk.eppojsclient.md)<!-- -->&gt;

2 changes: 1 addition & 1 deletion docs/js-client-sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ Used to access a singleton SDK precomputed client instance. Use the method after

</td><td>

Initializes the Eppo client with configuration parameters. This method should be called once on application startup. If an initialization is in process, calling `init` will return the in-progress `Promise<EppoClient>`<!-- -->. Once the initialization completes, calling `init` again will kick off the initialization routine (if `forceReinitialization` is `true`<!-- -->).
Initializes the Eppo client with configuration parameters. This method should be called once on application startup.


</td></tr>
Expand Down
9 changes: 6 additions & 3 deletions js-client-sdk.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,13 @@ export class EppoJSClient extends EppoClient {
getStringAssignment(flagKey: string, subjectKey: string, subjectAttributes: Record<string, AttributeType>, defaultValue: string): string;
// (undocumented)
getStringAssignmentDetails(flagKey: string, subjectKey: string, subjectAttributes: Record<string, AttributeType>, defaultValue: string): IAssignmentDetails<string>;
// @internal (undocumented)
init(config: Omit<IClientConfig, 'forceReinitialize'>): Promise<EppoJSClient>;
// (undocumented)
static initialized: boolean;
// (undocumented)
static instance: EppoJSClient;
// @internal (undocumented)
offlineInit(config: IClientConfigSync): void;
}

// @public
Expand Down Expand Up @@ -116,7 +119,7 @@ export { Flag }
export function getConfigUrl(apiKey: string, baseUrl?: string): URL;

// @public
export function getInstance(): EppoClient;
export function getInstance(): EppoJSClient;

// @public
export function getPrecomputedInstance(): EppoPrecomputedClient;
Expand Down Expand Up @@ -169,7 +172,7 @@ export interface IClientConfigSync {
}

// @public
export function init(config: IClientConfig): Promise<EppoClient>;
export function init(config: IClientConfig): Promise<EppoJSClient>;

// @public
export interface IPrecomputedClientConfig extends IBaseRequestConfig {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eppo/js-client-sdk",
"version": "3.9.8",
"version": "3.10.0",
"description": "Eppo SDK for client-side JavaScript applications",
"main": "dist/index.js",
"files": [
Expand Down
Loading
Loading