Skip to content

Commit 427ba88

Browse files
authored
feat!: use "domain" instead of "clientName" (#826)
## This PR - adds support for domains - removes named clients --------- Signed-off-by: Michael Beemer <[email protected]> Signed-off-by: Michael Beemer <[email protected]>
1 parent 5637cb2 commit 427ba88

File tree

2 files changed

+16
-20
lines changed

2 files changed

+16
-20
lines changed

packages/react/README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ The OpenFeature React SDK adds React-specific functionality to the [OpenFeature
4242

4343
In addition to the feature provided by the [web sdk](https://openfeature.dev/docs/reference/technologies/client/web), capabilities include:
4444

45-
- [Multiple Providers and Scoping](#multiple-providers-and-scoping)
45+
- [Multiple Providers and domains](#multiple-providers-and-domains)
4646
- [Re-rendering with Context Changes](#re-rendering-with-context-changes)
4747
- [Re-rendering with Flag Configuration Changes](#re-rendering-with-flag-configuration-changes)
4848
- [Suspense Support](#suspense-support)
@@ -130,15 +130,16 @@ const {
130130
} = useBooleanFlagDetails('new-message', false);
131131
```
132132

133-
### Multiple Providers and Scoping
133+
### Multiple Providers and Domains
134134

135-
Multiple providers and scoped clients can be configured by passing a `clientName` to the `OpenFeatureProvider`:
135+
136+
Multiple providers can be used by passing a `domain` to the `OpenFeatureProvider`:
136137

137138
```tsx
138-
// Flags within this scope will use the a client/provider associated with `myClient`,
139+
// Flags within this domain will use the a client/provider associated with `my-domain`,
139140
function App() {
140141
return (
141-
<OpenFeatureProvider clientName={'myClient'}>
142+
<OpenFeatureProvider domain={'my-domain'}>
142143
<Page></Page>
143144
</OpenFeatureProvider>
144145
);
@@ -148,9 +149,11 @@ function App() {
148149
This is analogous to:
149150

150151
```ts
151-
OpenFeature.getClient('myClient');
152+
OpenFeature.getClient('my-domain');
152153
```
153154

155+
For more information about `domains`, refer to the [web SDK](https://github.com/open-feature/js-sdk/blob/main/packages/client/README.md).
156+
154157
### Re-rendering with Context Changes
155158

156159
By default, if the OpenFeature [evaluation context](https://openfeature.dev/docs/reference/concepts/evaluation-context) is modified, components will be re-rendered.

packages/react/src/provider.tsx

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,32 @@
11
import * as React from 'react';
22
import { Client, OpenFeature } from '@openfeature/web-sdk';
33

4-
type ClientOrClientName =
4+
type ClientOrDomain =
55
| {
66
/**
7-
* The name of the client.
7+
* An identifier which logically binds clients with providers
88
* @see OpenFeature.setProvider() and overloads.
99
*/
10-
clientName: string;
11-
/**
12-
* OpenFeature client to use.
13-
*/
10+
domain: string;
1411
client?: never;
1512
}
1613
| {
1714
/**
1815
* OpenFeature client to use.
1916
*/
2017
client: Client;
21-
/**
22-
* The name of the client.
23-
* @see OpenFeature.setProvider() and overloads.
24-
*/
25-
clientName?: never;
18+
domain?: never;
2619
};
2720

2821
type ProviderProps = {
2922
children?: React.ReactNode;
30-
} & ClientOrClientName;
23+
} & ClientOrDomain;
3124

3225
const Context = React.createContext<Client | undefined>(undefined);
3326

34-
export const OpenFeatureProvider = ({ client, clientName, children }: ProviderProps) => {
27+
export const OpenFeatureProvider = ({ client, domain, children }: ProviderProps) => {
3528
if (!client) {
36-
client = OpenFeature.getClient(clientName);
29+
client = OpenFeature.getClient(domain);
3730
}
3831

3932
return <Context.Provider value={client}>{children}</Context.Provider>;

0 commit comments

Comments
 (0)