-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
1,271 additions
and
279 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
## API Report File for "@spotify-confidence/react" | ||
|
||
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). | ||
```ts | ||
|
||
import { Closer } from '@spotify-confidence/sdk'; | ||
import { Confidence } from '@spotify-confidence/sdk'; | ||
import { Configuration } from '@spotify-confidence/sdk'; | ||
import { Context } from '@spotify-confidence/sdk'; | ||
import { EventSender } from '@spotify-confidence/sdk'; | ||
import { FC } from 'react'; | ||
import { FlagEvaluation } from '@spotify-confidence/sdk'; | ||
import { FlagResolver } from '@spotify-confidence/sdk'; | ||
import { PropsWithChildren } from 'react'; | ||
import { State } from '@spotify-confidence/sdk'; | ||
import { StateObserver } from '@spotify-confidence/sdk'; | ||
import { Trackable } from '@spotify-confidence/sdk'; | ||
import { Value } from '@spotify-confidence/sdk'; | ||
|
||
// Warning: (ae-missing-release-tag) "ConfidenceProvider" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal) | ||
// Warning: (ae-missing-release-tag) "ConfidenceProvider" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal) | ||
// | ||
// @public (undocumented) | ||
export type ConfidenceProvider = FC<PropsWithChildren<{ | ||
confidence: Confidence; | ||
}>> & { | ||
WithContext: FC<PropsWithChildren<{ | ||
context: Context; | ||
}>>; | ||
}; | ||
|
||
// @public (undocumented) | ||
export const ConfidenceProvider: ConfidenceProvider; | ||
|
||
// Warning: (ae-missing-release-tag) "ConfidenceReact" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal) | ||
// | ||
// @public (undocumented) | ||
export class ConfidenceReact implements EventSender, Trackable, FlagResolver { | ||
constructor(delegate: Confidence); | ||
// (undocumented) | ||
clearContext(): void; | ||
// (undocumented) | ||
get config(): Configuration; | ||
// @internal (undocumented) | ||
readonly delegate: Confidence; | ||
// (undocumented) | ||
evaluateFlag<T extends Value>(path: string, defaultValue: T): FlagEvaluation<Value.Widen<T>>; | ||
// (undocumented) | ||
getContext(): Context; | ||
// (undocumented) | ||
getFlag<T extends Value>(path: string, defaultValue: T): Promise<Value.Widen<T>>; | ||
// (undocumented) | ||
setContext(context: Context): void; | ||
// @internal (undocumented) | ||
get state(): State; | ||
// (undocumented) | ||
subscribe(onStateChange?: StateObserver | undefined): () => void; | ||
// (undocumented) | ||
track(name: string, message?: Value.Struct): void; | ||
// (undocumented) | ||
track(manager: Trackable.Manager): Closer; | ||
// (undocumented) | ||
useEvaluateFlag<T extends Value>(path: string, defaultValue: T): FlagEvaluation<Value.Widen<T>>; | ||
// (undocumented) | ||
useFlag<T extends Value>(path: string, defaultValue: T): Value.Widen<T>; | ||
// (undocumented) | ||
useWithContext(context: Context): ConfidenceReact; | ||
// (undocumented) | ||
withContext(context: Context): ConfidenceReact; | ||
} | ||
|
||
// Warning: (ae-missing-release-tag) "useConfidence" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal) | ||
// | ||
// @public (undocumented) | ||
export const useConfidence: () => ConfidenceReact; | ||
|
||
// Warning: (ae-missing-release-tag) "useEvaluateFlag" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal) | ||
// | ||
// @public (undocumented) | ||
export function useEvaluateFlag<T extends Value>(path: string, defaultValue: T, confidence?: ConfidenceReact): FlagEvaluation<Value.Widen<T>>; | ||
|
||
// Warning: (ae-missing-release-tag) "useFlag" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal) | ||
// | ||
// @public (undocumented) | ||
export function useFlag<T extends Value>(path: string, defaultValue: T, confidence?: ConfidenceReact): Value.Widen<T>; | ||
|
||
// Warning: (ae-missing-release-tag) "useWithContext" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal) | ||
// | ||
// @public (undocumented) | ||
export function useWithContext(context: Context, confidence?: ConfidenceReact): ConfidenceReact; | ||
|
||
// (No @packageDocumentation comment for this package) | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,54 @@ | ||
import { useState } from 'react'; | ||
import { useStringFlagValue } from '@openfeature/react-sdk'; | ||
import { useConfidence } from './ConfidenceContext'; | ||
import { OpenFeature } from '@openfeature/web-sdk'; | ||
import { useConfidence } from '@spotify-confidence/react'; | ||
import { createContext, useContext, useState } from 'react'; | ||
|
||
const fakeContext = createContext(undefined); | ||
|
||
const TestComponent = () => { | ||
const str = useStringFlagValue('web-sdk-e2e-flag.str', 'default'); | ||
const [clickCount, setClickCount] = useState(0); | ||
const confidence = useConfidence({ component: 'Test' }); | ||
const confidence = useConfidence(); | ||
// const details = useFlagEvaluation('web-sdk-e2e-flag.str', 'default'); | ||
// const details = confidence.evaluateFlag('web-sdk-e2e-flag.str', 'default'); | ||
const details = confidence.useFlag('web-sdk-e2e-flag.str', 'default'); | ||
// const details = useFlagValue('web-sdk-e2e-flag.str', 'default'); | ||
return ( | ||
<> | ||
<p>The string flag value is: {str}</p> | ||
<p>The flag is: </p> | ||
<pre>{JSON.stringify(details, null, ' ')}</pre> | ||
<p>Click count is: {clickCount}</p> | ||
<button | ||
onClick={() => { | ||
OpenFeature.setContext({ targetingKey: `user-${Math.random()}` }); | ||
confidence.track('click'); | ||
setClickCount(value => value + 1); | ||
}} | ||
> | ||
Randomise OpenFeature Context | ||
Click | ||
</button> | ||
<button | ||
onClick={() => { | ||
let { targeting_key } = confidence.getContext(); | ||
console.log('got targeting key:', targeting_key); | ||
if (targeting_key === 'user-a') { | ||
targeting_key = 'user-b'; | ||
} else { | ||
targeting_key = 'user-a'; | ||
} | ||
confidence.setContext({ targeting_key }); | ||
}} | ||
> | ||
Randomise Context | ||
</button> | ||
</> | ||
); | ||
}; | ||
|
||
export default TestComponent; | ||
|
||
function isRendering(): boolean { | ||
try { | ||
// eslint-disable-next-line | ||
useContext(fakeContext); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
} |
Empty file.
Oops, something went wrong.