Skip to content
This repository has been archived by the owner on Sep 13, 2023. It is now read-only.

Commit

Permalink
update code snippets in README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
nickybondarenko committed Jul 24, 2023
1 parent 05e5fed commit cf4c64a
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ This will get a build from the head of the mentioned branch.
client.getBooleanValue("boolFlag", default = false)

// get a bool flag value async
openFeatureClient
.toAsync()
.observeBooleanValue(key, default)
.collect {
// do something with boolean
coroutineScope.launch {
WithContext(Dispatchers.IO) {
awaitProviderReady()
}
// read properties
}

// get bool flag with compose
val myBoolProperty = openFeatureClient
Expand All @@ -78,14 +78,6 @@ This will get a build from the head of the mentioned branch.
.collectAsState()
```

### Context-aware evaluation

Sometimes the value of a flag must take into account some dynamic criteria about the application or user, such as the user location, IP, email address, or the location of the server.
In OpenFeature, we refer to this as [`targeting`](https://openfeature.dev/specification/glossary#targeting).
If the flag system you're using supports targeting, you can provide the input data using the `EvaluationContext`.

<!-- TODO: code examples using context and different levels -->

### Events

Events allow you to react to state changes in the provider or underlying flag management system, such as flag definition changes, provider readiness, or error conditions.
Expand All @@ -94,11 +86,11 @@ Some providers support additional events, such as `PROVIDER_CONFIGURATION_CHANGE
Please refer to the documentation of the provider you're using to see what events are supported.

```kotlin
// to listen to PROVIDER_READY event
CoroutineScope(Dispatchers.IO).launch {
awaitProviderReady()
// now provider is ready, read the properties
}
EventHandler.eventsObserver()
.observe<OpenFeatureEvents.ProviderReady>()
.collect {
// do something once the provider is ready
}
```

### Providers:
Expand Down Expand Up @@ -150,11 +142,11 @@ class NewProvider(override val hooks: List<Hook<*>>, override val metadata: Meta
// resolve a string flag value
}

override suspend fun initialize(initialContext: EvaluationContext?) {
override fun initialize(initialContext: EvaluationContext?) {
// add context-aware provider initialisation
}

override suspend fun onContextSet(oldContext: EvaluationContext?, newContext: EvaluationContext) {
override fun onContextSet(oldContext: EvaluationContext?, newContext: EvaluationContext) {
// add necessary changes on context change
}

Expand Down

0 comments on commit cf4c64a

Please sign in to comment.