From cf4c64a9a2d1137777bfa7057322a73518518ac1 Mon Sep 17 00:00:00 2001 From: Nicky Bondarenko Date: Mon, 24 Jul 2023 17:28:30 +0200 Subject: [PATCH] update code snippets in README.md --- README.md | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 8032727..92ddfda 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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`. - - - ### 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. @@ -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() + .collect { + // do something once the provider is ready + } ``` ### Providers: @@ -150,11 +142,11 @@ class NewProvider(override val hooks: List>, 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 }