1- import React , { createContext , useContext , useRef } from 'react' ;
1+ import React , { createContext , useRef } from 'react' ;
22import type { types } from '@mongodb-js/mdb-experiment-js' ;
3- import type { typesReact } from '@mongodb-js/mdb-experiment-js/react' ;
43import type { ExperimentTestName } from './growth-experiments' ;
54
6- type UseAssignmentHook = (
7- experimentName : ExperimentTestName ,
8- trackIsInSample : boolean ,
9- options ?: typesReact . UseAssignmentOptions < types . TypeData >
10- ) => typesReact . UseAssignmentResponse < types . TypeData > ;
11-
125type AssignExperimentFn = (
136 experimentName : ExperimentTestName ,
147 options ?: types . AssignOptions < string >
@@ -21,22 +14,11 @@ type GetAssignmentFn = (
2114) => Promise < types . SDKAssignment < ExperimentTestName , string > | null > ;
2215
2316interface CompassExperimentationProviderContextValue {
24- useAssignment : UseAssignmentHook ;
2517 assignExperiment : AssignExperimentFn ;
2618 getAssignment : GetAssignmentFn ;
2719}
2820
2921const initialContext : CompassExperimentationProviderContextValue = {
30- useAssignment ( ) {
31- return {
32- assignment : null ,
33- asyncStatus : null ,
34- error : null ,
35- isLoading : false ,
36- isError : false ,
37- isSuccess : true ,
38- } ;
39- } ,
4022 assignExperiment ( ) {
4123 return Promise . resolve ( null ) ;
4224 } ,
@@ -51,18 +33,15 @@ export const ExperimentationContext =
5133// Provider component that accepts MMS experiment utils as props
5234export const CompassExperimentationProvider : React . FC < {
5335 children : React . ReactNode ;
54- useAssignment : UseAssignmentHook ;
5536 assignExperiment : AssignExperimentFn ;
5637 getAssignment : GetAssignmentFn ;
57- } > = ( { children, useAssignment , assignExperiment, getAssignment } ) => {
38+ } > = ( { children, assignExperiment, getAssignment } ) => {
5839 // Use useRef to keep the functions up-to-date; Use mutation pattern to maintain the
5940 // same object reference to prevent unnecessary re-renders of consuming components
6041 const { current : contextValue } = useRef ( {
61- useAssignment,
6242 assignExperiment,
6343 getAssignment,
6444 } ) ;
65- contextValue . useAssignment = useAssignment ;
6645 contextValue . assignExperiment = assignExperiment ;
6746 contextValue . getAssignment = getAssignment ;
6847
@@ -72,8 +51,3 @@ export const CompassExperimentationProvider: React.FC<{
7251 </ ExperimentationContext . Provider >
7352 ) ;
7453} ;
75-
76- // Hook for components to access experiment assignment
77- export const useAssignment = ( ...args : Parameters < UseAssignmentHook > ) => {
78- return useContext ( ExperimentationContext ) . useAssignment ( ...args ) ;
79- } ;
0 commit comments