Skip to content

Commit

Permalink
Update services
Browse files Browse the repository at this point in the history
  • Loading branch information
ashevchuk-ecw committed Feb 29, 2024
1 parent 4f37d3e commit ae974b5
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 39 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"build": "ng build st-client-lib && ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test"
},
Expand Down
26 changes: 14 additions & 12 deletions projects/st-client-lib/src/lib/st-client-lib.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from '@angular/core';
import { default as Statsig, DynamicConfig } from 'statsig-js';
import Statsig, { DynamicConfig } from 'statsig-js';

@Injectable({
providedIn: 'root'
Expand All @@ -8,9 +8,9 @@ export class StClientLibService {

constructor() { }

public async statsigInit(): Promise<void> {
await Statsig.initialize(
'',
public async statsigInit(key: string): Promise<void> {
Statsig.initialize(
key,
{
appVersion: '42',
custom: {
Expand All @@ -20,14 +20,16 @@ export class StClientLibService {
locale: 'UA',
},
{ environment: { tier: 'development' } }
);
}
).then(() => {
console.log('done');
});
}

public isFeatureEnabled(key: string): boolean {
return Statsig.checkGate(key);
}
public isFeatureEnabled(key: string): boolean {
return Statsig.checkGate(key);
}

public getExperiment(experimentName: string): DynamicConfig {
return Statsig.getExperiment(experimentName);;
}
public getExperiment(experimentName: string): DynamicConfig {
return Statsig.getExperiment(experimentName);;
}
}
6 changes: 4 additions & 2 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
<hr>

<button (click)="initStatsig()">Init Statsig</button>
<button (click)="initStatsigFromService()">Init Statsig From Service</button>
<hr>
<button (click)="getExperiment('image_search_aa_experiment')">Get experiment</button>
<button (click)="getExperimentFromService('image_search_aa_experiment')">Get experiment From Service</button>
<hr>
<button (click)="initDepsStatsig()">Init Deps Statsig</button>
<hr>
<button (click)="getDepsExperiment('image_search_aa_experiment')">Get deps experiment</button>
36 changes: 12 additions & 24 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component } from '@angular/core';
import { StService } from './statsig.service';
import { StClientLibService } from 'st-client-lib';
import { default as Statsig, DynamicConfig } from 'statsig-js';

@Component({
selector: 'app-root',
Expand All @@ -10,40 +10,28 @@ import { default as Statsig, DynamicConfig } from 'statsig-js';
export class AppComponent {
title = 'statsig-client';

constructor(private stService: StClientLibService) {
constructor(
private localStatsigService: StService,
private depsStatsigService: StClientLibService
) {

}

public async statsigInit() {
await Statsig.initialize(
'client-C1rOhOyc5O1TqQIpY3MCp5wCtjfxlXMsUvQSTnKqPi4',
{
appVersion: '42',
custom: {
appName: 'Statsig POC'
},
userID: '17322425',
locale: 'UA',
},
{ environment: { tier: 'development' } }
);
public async initStatsig() {
await this.localStatsigService.statsigInit();
}

public initStatsig() {
this.statsigInit();
public async initDepsStatsig() {
await this.depsStatsigService.statsigInit('');
}

public initStatsigFromService() {
this.stService.statsigInit();
}

public getExperimentFromService(experimentName: string) {
const dc = this.stService.getExperiment(experimentName);
public getDepsExperiment(experimentName: string) {
const dc = this.depsStatsigService.getExperiment(experimentName);
console.log(`Experiment: ${experimentName}:`, dc);
}

public getExperiment(experimentName: string) {
const dc = Statsig.getExperiment(experimentName);
const dc = this.localStatsigService.getExperiment(experimentName);
console.log(`Experiment: ${experimentName}:`, dc);
}
}
35 changes: 35 additions & 0 deletions src/app/statsig.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Injectable } from '@angular/core';
import Statsig, { DynamicConfig } from 'statsig-js';

@Injectable({
providedIn: 'root'
})
export class StService {

constructor() { }

public async statsigInit(): Promise<void> {
Statsig.initialize(
'client-C1rOhOyc5O1TqQIpY3MCp5wCtjfxlXMsUvQSTnKqPi4',
{
appVersion: '42',
custom: {
appName: 'Statsig POC'
},
userID: '17322425',
locale: 'UA',
},
{ environment: { tier: 'development' } }
).then(() => {
console.log('done');
});
}

public isFeatureEnabled(key: string): boolean {
return Statsig.checkGate(key);
}

public getExperiment(experimentName: string): DynamicConfig {
return Statsig.getExperiment(experimentName);;
}
}

0 comments on commit ae974b5

Please sign in to comment.