You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## This PR
Adds docs to JavaScript web-client sdk regarding flag evaluation flow
and context.
### Related Issues
Closes#570
### Notes
Mermaid diagrams were used but I'm not sure if they are currently
supported.
---------
Signed-off-by: Luiz Ribeiro <ltrindaderibeiro@gmail.com>
| ✅ |[Providers](#providers)| Integrate with a commercial, open source, or in-house feature management tool. |
94
-
| ✅ |[Targeting](#targeting)| Contextually-aware flag evaluation using [evaluation context](https://openfeature.dev/docs/reference/concepts/evaluation-context). |
94
+
| ✅ |[Targeting](#targeting-and-context)| Contextually-aware flag evaluation using [evaluation context](https://openfeature.dev/docs/reference/concepts/evaluation-context). |
95
95
| ✅ |[Hooks](#hooks)| Add functionality to various stages of the flag evaluation life-cycle. |
96
96
| ✅ |[Logging](#logging)| Integrate with popular logging packages. |
97
97
| ✅ |[Named clients](#named-clients)| Utilize multiple providers in a single application. |
In some situations, it may be beneficial to register multiple providers in the same application.
117
117
This is possible using [named clients](#named-clients), which is covered in more detail below.
118
118
119
-
### Targeting
119
+
### Flag evaluation flow
120
+
121
+
When a new provider is added to OpenFeature client the following process happens:
122
+
123
+
```mermaid
124
+
sequenceDiagram
125
+
autonumber
126
+
Client-->+Feature Flag Provider: ResolveAll (context)
127
+
Feature Flag Provider-->-Client: Flags values
128
+
```
129
+
130
+
In (1) the Client sends a request to the provider backend in order to get all values from all feature flags that it has.
131
+
Once the provider backend replies (2) the client holds all flag values and therefore the flag evaluation process is synchronous.
132
+
133
+
In order to prevent flag evaluation to the default value while flags are still being fetched, it is highly recommended to only look for flag value after the provider has emitted the `Ready` event.
Sometimes, the value of a flag must consider some dynamic criteria about the application or user, such as the user's location, IP, email address, or the server's location.
122
153
In OpenFeature, we refer to this as [targeting](https://openfeature.dev/specification/glossary#targeting).
@@ -127,6 +158,10 @@ If the flag management system you're using supports targeting, you can provide t
Providers may implement an `onContextChanged` method that receives the old context and the newer one.
163
+
This method is used internally by the provider to detect if, given the context change, the flags values cached on client side are invalid. If needed a request will be made to the provider with the new context in order to get the correct flags values.
164
+
130
165
### Hooks
131
166
132
167
[Hooks](https://openfeature.dev/docs/reference/concepts/hooks) allow for custom logic to be added at well-defined points of the flag evaluation life-cycle
@@ -161,7 +196,7 @@ import type { Logger } from "@openfeature/web-sdk";
161
196
// The logger can be anything that conforms with the Logger interface
0 commit comments