Skip to content

Commit 1be7560

Browse files
Merge pull request #19 from splitio/main
update dev
2 parents f116e26 + 6ebc78b commit 1be7560

File tree

1 file changed

+163
-16
lines changed

1 file changed

+163
-16
lines changed

README.md

Lines changed: 163 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Split OpenFeature Provider for NodeJS
1+
# Split OpenFeature Provider for Web JavaScript
22
[![Twitter Follow](https://img.shields.io/twitter/follow/splitsoftware.svg?style=social&label=Follow&maxAge=1529000)](https://twitter.com/intent/follow?screen_name=splitsoftware)
33

44
## Overview
@@ -27,11 +27,17 @@ import { OpenFeatureSplitProvider } from '@splitsoftware/openfeature-web-split-p
2727

2828
const splitFactory = SplitFactory({
2929
core: {
30-
authorizationKey: 'your auth key'
30+
authorizationKey: 'CLIENT_SIDE_SDK_KEY',
31+
key: 'TARGETING_KEY'
3132
}
3233
});
34+
3335
const provider = new OpenFeatureSplitProvider(splitFactory);
34-
OpenFeature.setProvider(provider);
36+
37+
// Register provider and wait for the default SDK client for 'TARGETING_KEY' to be ready
38+
await OpenFeature.setProviderAndWait(provider);
39+
40+
const client = OpenFeature.getClient();
3541
```
3642

3743
## Use of OpenFeature with Split
@@ -43,7 +49,7 @@ const context: EvaluationContext = {
4349
targetingKey: 'TARGETING_KEY',
4450
trafficType: 'account'
4551
};
46-
OpenFeature.setContext(context)
52+
await OpenFeature.setContext(context)
4753
```
4854

4955
## Evaluate with details
@@ -62,10 +68,11 @@ Evaluation attributes must be set in context before evaluation
6268
const context: EvaluationContext = {
6369
targetingKey: 'TARGETING_KEY',
6470
trafficType: 'account',
71+
// Evaluation attributes:
6572
plan: 'premium',
66-
couppon: 'WELCOME10'
73+
coupon: 'WELCOME10'
6774
};
68-
OpenFeature.setContext(context);
75+
await OpenFeature.setContext(context);
6976
const booleanTreatment = client.getBooleanDetails('boolFlag', false);
7077
```
7178

@@ -89,11 +96,152 @@ Example:
8996
const context = { targetingKey: 'user-123', trafficType: 'account' }
9097
const details = { value: 19.99, properties: { plan: 'pro', coupon: 'WELCOME10' }}
9198

92-
client.setEvaluationContext(context)
99+
await OpenFeature.setContext(context)
93100
client.track('checkout.completed', details)
94101
```
102+
103+
## Angular Usage
104+
105+
### Install dependencies
106+
```bash
107+
npm i @openfeature/angular-sdk @splitsoftware/splitio-browserjs @splitsoftware/openfeature-web-split-provider
108+
```
109+
110+
### Initialize the Angular SDK
111+
112+
#### Traditional (NgModule) setup
113+
```js
114+
import { NgModule } from '@angular/core';
115+
import { RouterModule, Routes } from '@angular/router';
116+
import { OpenFeatureModule } from '@openfeature/angular-sdk';
117+
import { SplitFactory } from '@splitsoftware/splitio-browserjs';
118+
import { OpenFeatureSplitProvider } from '@splitsoftware/openfeature-web-split-provider';
119+
120+
const splitFactory = SplitFactory({
121+
core: {
122+
authorizationKey: 'CLIENT_SIDE_SDK_KEY',
123+
key: 'TARGETING_KEY'
124+
}
125+
});
126+
const openFeatureProvider = new OpenFeatureSplitProvider(splitFactory);
127+
128+
@NgModule({
129+
imports: [
130+
RouterModule.forRoot(routes),
131+
OpenFeatureModule.forRoot({
132+
provider: openFeatureProvider
133+
})
134+
],
135+
bootstrap: [AppComponent]
136+
})
137+
export class AppModule {}
138+
```
139+
140+
#### Standalone (Angular 16+) setup
141+
```js
142+
import { ApplicationConfig, provideBrowserGlobalErrorListeners, importProvidersFrom } from '@angular/core';
143+
import { OpenFeatureModule } from '@openfeature/angular-sdk';
144+
import { SplitFactory } from '@splitsoftware/splitio-browserjs';
145+
import { OpenFeatureSplitProvider } from '@splitsoftware/openfeature-web-split-provider';
146+
147+
const splitFactory = SplitFactory({
148+
core: {
149+
authorizationKey: 'CLIENT_SIDE_SDK_KEY',
150+
key: 'TARGETING_KEY'
151+
}
152+
});
153+
const openFeatureProvider = new OpenFeatureSplitProvider(splitFactory);
154+
155+
export const appConfig: ApplicationConfig = {
156+
providers: [
157+
provideBrowserGlobalErrorListeners(),
158+
importProvidersFrom(
159+
OpenFeatureModule.forRoot({
160+
provider: openFeatureProvider
161+
})
162+
)
163+
]
164+
};
165+
```
166+
167+
#### Component injection and usage
168+
```js
169+
import { FeatureFlagService, EvaluationDetails } from '@openfeature/angular-sdk';
170+
171+
@Component({
172+
selector: 'app-root',
173+
imports: [RouterOutlet],
174+
templateUrl: './app.html',
175+
styleUrl: './app.css'
176+
})
177+
export class App {
178+
constructor(private splitService: FeatureFlagService) {}
179+
180+
ngOnInit() {
181+
this.splitService.getStringDetails('featureFlagName', 'default').subscribe((result: EvaluationDetails<string>) => {
182+
console.log('Feature flag result:', result.value);
183+
});
184+
}
185+
}
186+
```
187+
> 🔗 For more information on Angular integration, visit the [official OpenFeature Angular SDK documentation][angular-docs].
188+
189+
[angular-docs]: https://openfeature.dev/docs/reference/sdks/client/web/angular
190+
191+
## React usage
192+
193+
### Install dependencies
194+
```bash
195+
npm i @openfeature/react-sdk @splitsoftware/splitio-browserjs @splitsoftware/openfeature-web-split-provider
196+
```
197+
198+
### Initialize the React SDK
199+
```js
200+
import { OpenFeature } from '@openfeature/react-sdk';
201+
import { OpenFeatureSplitProvider } from '@splitsoftware/openfeature-web-split-provider';
202+
import { DebugLogger, SplitFactory } from '@splitsoftware/splitio-browserjs';
203+
204+
const splitFactory = SplitFactory({
205+
core: {
206+
authorizationKey: 'CLIENT_SIDE_SDK_KEY',
207+
key: 'TARGETING_KEY'
208+
}
209+
})
210+
const openFeatureProvider = new OpenFeatureSplitProvider(splitFactory);
211+
212+
OpenFeature.setProvider(openFeatureProvider);
213+
214+
function App() {
215+
return (
216+
<OpenFeatureProvider>
217+
<Page></Page>
218+
</OpenFeatureProvider>
219+
);
220+
}
221+
```
222+
223+
#### Evaluation hooks
224+
```js
225+
import { useFlag } from '@openfeature/react-sdk';
226+
227+
function Page() {
228+
// Use the "query-style" flag evaluation hook, specifying a flag-key and a default value.
229+
const { value: showNewMessage } = useFlag('new-message', true);
230+
return (
231+
<div className="App">
232+
<header className="App-header">
233+
{showNewMessage ? <p>Welcome to this OpenFeature-enabled React app!</p> : <p>Welcome to this React app.</p>}
234+
</header>
235+
</div>
236+
)
237+
}
238+
```
239+
> 🔗 For more information on React integration, visit the [official OpenFeature React SDK documentation][react-docs].
240+
241+
[react-docs]: https://openfeature.dev/docs/reference/sdks/client/web/react
242+
95243
## Submitting issues
96-
244+
97245
The Split team monitors all issues submitted to this [issue tracker](https://github.com/splitio/split-openfeature-provider-web-js/issues). We encourage you to use this issue tracker to submit any bug reports, feedback, and feature enhancements. We'll do our best to respond in a timely manner.
98246

99247
## Contributing
@@ -103,13 +251,13 @@ Please see [Contributors Guide](CONTRIBUTORS-GUIDE.md) to find all you need to s
103251
Licensed under the Apache License, Version 2.0. See: [Apache License](http://www.apache.org/licenses/).
104252

105253
## About Split
106-
254+
107255
Split is the leading Feature Delivery Platform for engineering teams that want to confidently deploy features as fast as they can develop them. Split’s fine-grained management, real-time monitoring, and data-driven experimentation ensure that new features will improve the customer experience without breaking or degrading performance. Companies like Twilio, Salesforce, GoDaddy and WePay trust Split to power their feature delivery.
108-
256+
109257
To learn more about Split, contact hello@split.io, or get started with feature flags for free at https://www.split.io/signup.
110-
258+
111259
Split has built and maintains SDKs for:
112-
260+
113261
* .NET [Github](https://github.com/splitio/dotnet-client) [Docs](https://help.split.io/hc/en-us/articles/360020240172--NET-SDK)
114262
* Android [Github](https://github.com/splitio/android-client) [Docs](https://help.split.io/hc/en-us/articles/360020343291-Android-SDK)
115263
* Angular [Github](https://github.com/splitio/angular-sdk-plugin) [Docs](https://help.split.io/hc/en-us/articles/6495326064397-Angular-utilities)
@@ -128,10 +276,9 @@ Split has built and maintains SDKs for:
128276
* React Native [Github](https://github.com/splitio/react-native-client) [Docs](https://help.split.io/hc/en-us/articles/4406066357901-React-Native-SDK)
129277
* Redux [Github](https://github.com/splitio/redux-client) [Docs](https://help.split.io/hc/en-us/articles/360038851551-Redux-SDK)
130278
* Ruby [Github](https://github.com/splitio/ruby-client) [Docs](https://help.split.io/hc/en-us/articles/360020673251-Ruby-SDK)
131-
279+
132280
For a comprehensive list of open source projects visit our [Github page](https://github.com/splitio?utf8=%E2%9C%93&query=%20only%3Apublic%20).
133-
281+
134282
**Learn more about Split:**
135-
136-
Visit [split.io/product](https://www.split.io/product) for an overview of Split, or visit our documentation at [help.split.io](http://help.split.io) for more detailed information.
137283

284+
Visit [split.io/product](https://www.split.io/product) for an overview of Split, or visit our documentation at [help.split.io](http://help.split.io) for more detailed information.

0 commit comments

Comments
 (0)