Skip to content

Commit

Permalink
fix(configs): add localStorage fallback cache for initialization method
Browse files Browse the repository at this point in the history
feature/add-localstorage-cache
  • Loading branch information
samwx committed Jun 10, 2021
1 parent a61c645 commit 6dc2630
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
11 changes: 5 additions & 6 deletions src/FeatureToggleApiService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { AddUserRequest } from './types/AddUserRequest';
import { UserAccount } from './types/UserAccount';
import { IFeatureToggleServiceSettings } from './types/IFeatureToggleServiceSettings';
import { Instruction } from './types/Instruction';

const axios = require('axios').default;
import axios from 'axios';

export class FeatureToggleApiService {
private readonly API_URL = 'https://app.launchdarkly.com/api/v2/flags';
Expand Down Expand Up @@ -38,13 +37,13 @@ export class FeatureToggleApiService {
instructions.push(new Instruction({
kind: this.ADD_USER_TARGETS,
values: users.map(user => user.email),
variationId: variationId
variationId
}));

const addUserRequest = new AddUserRequest({
comment: this.DEFAULT_COMMENT,
environmentKey: this.settings.environmentKey,
instructions: instructions
instructions
});

return addUserRequest;
Expand All @@ -56,8 +55,8 @@ export class FeatureToggleApiService {
headers: this.getApiRequestHeaders()
});
if (response.status === this.STATUS_CODE_OK) {
const variation = response.data.variations.find(variation => {
return variation.value === true;
const variation = response.data.variations.find(({ value }) => {
return value === true;
});
return variation._id;
}
Expand Down
5 changes: 4 additions & 1 deletion src/FeatureToggleInstanceFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ const applicationByCluster = (p: any) =>

export class FeatureToggleInstanceFactory {
private client: LDClient;
private defaultOptions: Partial<LDOptions> = {
bootstrap: 'localStorage'
};

constructor(payload: UserAccount | Application, ldclientSdkKey: string, options?: LDOptions) {
this.client = initialize(ldclientSdkKey, this.payloadByType(payload), options);
this.client = initialize(ldclientSdkKey, this.payloadByType(payload), { ...options, ...this.defaultOptions });
}

/**
Expand Down

0 comments on commit 6dc2630

Please sign in to comment.