Skip to content

Commit

Permalink
chore: updating snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-statsig committed Mar 18, 2024
1 parent eb39178 commit 6d69387
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
2 changes: 1 addition & 1 deletion packages/client-core/src/StatsigDataAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type DataAdapterCommon = {

export type EvaluationsDataAdapter = DataAdapterCommon & {
/**
* Synchronously get evaluation data for the given user. Called during initializeSync and/or updateUserSync.
* Synchronously get evaluation data for the given user. Called during initializeSync and/or updateUserSync.
*
* It is also called during async update operations before StatsigDataAdapter.getDataAsync is called.
* @param {StatsigUser} user The StatsigUser to get data for.
Expand Down
7 changes: 4 additions & 3 deletions samples/react/src/SamplesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import Prism from 'prismjs';
import { ReactNode, useEffect, useState } from 'react';

const SAMPLES = [
// React
() => import('./samples/react-precomp/sample-react-login'),

// Precomputed Evaluations Client
() => import('./samples/precomputed-client/sample-precomp-initialize'),
() => import('./samples/precomputed-client/sample-precomp-basic'),
Expand All @@ -22,6 +19,10 @@ const SAMPLES = [
() => import('./samples/precomputed-client/sample-precomp-log-event'),
() => import('./samples/precomputed-client/sample-precomp-shutdown'),
() => import('./samples/precomputed-client/sample-precomp-bootstrap'),
() => import('./samples/precomputed-client/sample-precomp-get-data-adapter'),

// React
() => import('./samples/react-precomp/sample-react-login'),

() => import('./samples/OnDeviceClientBasic'),
];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
/* eslint-disable @typescript-eslint/no-unused-vars */

/* eslint-disable no-console */
// <snippet>
import { EvaluationsDataAdapter } from '@statsig/client-core';
import {
StatsigClient,
StatsigEvaluationsDataAdapter,
} from '@statsig/js-client';

// </snippet>
import { STATSIG_CLIENT_KEY as YOUR_CLIENT_KEY } from '../../Contants';
import { myStatsigClient } from './sample-precomp-instance';

Expand All @@ -17,22 +14,22 @@ class MyCustomEvalDataAdapter extends StatsigEvaluationsDataAdapter {}
// prettier-ignore
export default async function Sample(): Promise<void> {
// <snippet>

// Get the adapter
const dataAdapter = myStatsigClient.dataAdapter;
// </snippet>

return Promise.resolve();
}

// prettier-ignore
function foo() {
// Creating your own instance during startup
const myDataAdapter = new MyCustomEvalDataAdapter();
const myStatsigClient = new StatsigClient(
YOUR_CLIENT_KEY,
{ userID: 'a-user' },
{ dataAdapter: myDataAdapter }, // <- Pass the data adapter via StatsigOptions
);
// <snippet>

// Or, get the adapter at some later point
// </snippet>
// Or, use your own custom implementation
const myDataAdapter = new MyCustomEvalDataAdapter();
const myStatsigClient = new StatsigClient(
YOUR_CLIENT_KEY,
{ userID: 'a-user' },
{ dataAdapter: myDataAdapter }, // <- Pass the data adapter in via StatsigOptions
);
// </snippet>
}

0 comments on commit 6d69387

Please sign in to comment.