1
- import { EventSender , Trackable , FlagResolver , Confidence , Configuration , Value , Closer , Context , StateObserver , FlagEvaluation } from '@spotify-confidence/sdk' ;
2
- import { FC , PropsWithChildren } from 'react' ;
1
+ import { ConfidenceOptions , Confidence , Context , FlagEvaluation , Value } from '@spotify-confidence/sdk' ;
2
+ import { FC , PropsWithChildren , FunctionComponent , ReactNode } from 'react' ;
3
3
4
- /**
5
- * Confidence React instance
6
- * @public
7
- */
8
- declare class ConfidenceReact implements EventSender , Trackable , FlagResolver {
9
- /**
10
- * Confidence Delegate
11
- * @internal */
12
- readonly delegate : Confidence ;
13
- constructor ( delegate : Confidence ) ;
14
- /** Return configurations of the Confidence instance */
15
- get config ( ) : Configuration ;
16
- /**
17
- * Current serialized Context
18
- * @internal */
19
- get contextState ( ) : string ;
20
- /**
21
- * Tracks an event
22
- * @param name - event name
23
- * @param message - data to track */
24
- track ( name : string , message ?: Value . Struct ) : void ;
25
- /**
26
- * Tracks an event
27
- * @param manager - trackable manager */
28
- track ( manager : Trackable . Manager ) : Closer ;
29
- /** Returns context of the current Confidence instance */
30
- getContext ( ) : Context ;
31
- /** Set Confidence context */
32
- setContext ( context : Context , { transition } ?: {
33
- transition ?: boolean | undefined ;
34
- } ) : void ;
35
- /** Subscribe to flag changes in Confidence */
36
- subscribe ( onStateChange ?: StateObserver | undefined ) : ( ) => void ;
37
- /** Clears context of current Confidence instance */
38
- clearContext ( { transition } ?: {
39
- transition ?: boolean | undefined ;
40
- } ) : void ;
41
- /**
42
- * Creates a new ConfidenceReact instance with context
43
- * @param context - Confidence context
44
- * @returns ConfidenceReact instance
45
- */
46
- withContext ( context : Context ) : ConfidenceReact ;
47
- /** Evaluates a flag */
48
- evaluateFlag ( path : string , defaultValue : string ) : FlagEvaluation < string > ;
49
- evaluateFlag ( path : string , defaultValue : boolean ) : FlagEvaluation < boolean > ;
50
- evaluateFlag ( path : string , defaultValue : number ) : FlagEvaluation < number > ;
51
- evaluateFlag < T extends Value > ( path : string , defaultValue : T ) : FlagEvaluation < T > ;
52
- /** Returns flag value for a given flag */
53
- getFlag ( path : string , defaultValue : string ) : Promise < string > ;
54
- getFlag ( path : string , defaultValue : boolean ) : Promise < boolean > ;
55
- getFlag ( path : string , defaultValue : number ) : Promise < number > ;
56
- getFlag < T extends Value > ( path : string , defaultValue : T ) : Promise < T > ;
57
- /** Hook to access Context */
58
- useContext ( ) : Context ;
59
- /** Hook to access the WithContext functionality. Returns a ConfidenceReact instance with the passed context. */
60
- useWithContext ( context : Context ) : ConfidenceReact ;
61
- /** Hook to use EvaluateFlag functionality */
62
- useEvaluateFlag ( path : string , defaultValue : string ) : FlagEvaluation < string > ;
63
- useEvaluateFlag ( path : string , defaultValue : number ) : FlagEvaluation < number > ;
64
- useEvaluateFlag ( path : string , defaultValue : boolean ) : FlagEvaluation < boolean > ;
65
- useEvaluateFlag < T extends Value > ( path : string , defaultValue : T ) : FlagEvaluation < T > ;
66
- /** Hook to use getFlag functionality */
67
- useFlag ( path : string , defaultValue : string ) : string ;
68
- useFlag ( path : string , defaultValue : number ) : number ;
69
- useFlag ( path : string , defaultValue : boolean ) : boolean ;
70
- useFlag < T extends Value > ( path : string , defaultValue : T ) : T ;
71
- private assertContext ;
72
- }
4
+ declare const ManagedConfidenceProvider : FC < PropsWithChildren < {
5
+ options : ConfidenceOptions ;
6
+ } > > ;
73
7
/**
74
8
* Confidence Provider for React
75
9
* @public
76
10
*/
77
- type ConfidenceProvider = FC < PropsWithChildren < {
11
+ interface ConfidenceProvider extends FunctionComponent < {
78
12
confidence : Confidence ;
79
- } > > & {
13
+ children ?: ReactNode ;
14
+ } > {
80
15
WithContext : FC < PropsWithChildren < {
81
16
context : Context ;
82
17
} > > ;
83
- } ;
18
+ }
84
19
/**
85
20
* Confidence Provider for React
86
21
* @public
@@ -90,31 +25,31 @@ declare const ConfidenceProvider: ConfidenceProvider;
90
25
* Enables using Confidence
91
26
* @public
92
27
*/
93
- declare const useConfidence : ( ) => ConfidenceReact ;
28
+ declare const useConfidence : ( ) => Confidence ;
94
29
/**
95
30
* Use with given Confidence Context
96
31
* @public
97
32
*/
98
- declare function useWithContext ( context : Context , parent ?: ConfidenceReact ) : ConfidenceReact ;
33
+ declare function useWithContext ( context : Context , parent ?: Confidence ) : Confidence ;
99
34
/**
100
35
* Use Confidence Context
101
36
* @public
102
37
*/
103
- declare function useConfidenceContext ( confidence ?: ConfidenceReact ) : Context ;
38
+ declare function useConfidenceContext ( confidence ?: Confidence ) : Context ;
104
39
/**
105
40
* Use EvaluateFlag
106
41
* @public */
107
- declare function useEvaluateFlag ( path : string , defaultValue : string , confidence ?: ConfidenceReact ) : FlagEvaluation < string > ;
108
- declare function useEvaluateFlag ( path : string , defaultValue : number , confidence ?: ConfidenceReact ) : FlagEvaluation < number > ;
109
- declare function useEvaluateFlag ( path : string , defaultValue : boolean , confidence ?: ConfidenceReact ) : FlagEvaluation < boolean > ;
110
- declare function useEvaluateFlag < T extends Value > ( path : string , defaultValue : T , confidence ?: ConfidenceReact ) : FlagEvaluation < T > ;
42
+ declare function useEvaluateFlag ( path : string , defaultValue : string , confidence ?: Confidence ) : FlagEvaluation < string > ;
43
+ declare function useEvaluateFlag ( path : string , defaultValue : number , confidence ?: Confidence ) : FlagEvaluation < number > ;
44
+ declare function useEvaluateFlag ( path : string , defaultValue : boolean , confidence ?: Confidence ) : FlagEvaluation < boolean > ;
45
+ declare function useEvaluateFlag < T extends Value > ( path : string , defaultValue : T , confidence ?: Confidence ) : FlagEvaluation < T > ;
111
46
/**
112
47
* Use Flag
113
48
* @public
114
49
*/
115
- declare function useFlag ( path : string , defaultValue : string , confidence ?: ConfidenceReact ) : string ;
116
- declare function useFlag ( path : string , defaultValue : number , confidence ?: ConfidenceReact ) : number ;
117
- declare function useFlag ( path : string , defaultValue : boolean , confidence ?: ConfidenceReact ) : boolean ;
118
- declare function useFlag < T extends Value > ( path : string , defaultValue : T , confidence ?: ConfidenceReact ) : T ;
50
+ declare function useFlag ( path : string , defaultValue : string , confidence ?: Confidence ) : string ;
51
+ declare function useFlag ( path : string , defaultValue : number , confidence ?: Confidence ) : number ;
52
+ declare function useFlag ( path : string , defaultValue : boolean , confidence ?: Confidence ) : boolean ;
53
+ declare function useFlag < T extends Value > ( path : string , defaultValue : T , confidence ?: Confidence ) : T ;
119
54
120
- export { ConfidenceProvider , ConfidenceReact , useConfidence , useConfidenceContext , useEvaluateFlag , useFlag , useWithContext } ;
55
+ export { ConfidenceProvider , ManagedConfidenceProvider , useConfidence , useConfidenceContext , useEvaluateFlag , useFlag , useWithContext } ;
0 commit comments