Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Spec putContext / track(ConfidenceContextProducer) #175

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,25 @@ To avoid waiting on backend calls when the Application starts, the suggested app
`confidence.activate()` and then trigger a background refresh via `confidence.asyncFetch()` for future sessions.

### Setting the context
The context is a key-value map used for sampling and for targeting, when flag are evaluated by the Confidence backend.
The context is a key-value map used for sampling and for targeting, when flags are evaluated by the Confidence backend.
It is also appended to the tracked events, making it a great way to create dimensions for metrics in Confidence.

```swift
confidence.putContext(context: ["key": ConfidenceValue(string: "value")])
```

Note that a `ConfidenceValue` is accepted a map values, which has a constructor for all the value types
supported by Confidence.
Another way to configure the context involves using the `track` API:
```swift
confidence.track(producer: contextProducerImplementation)
```

The "producer" conforms to `ConfidenceContextProducer`, which allows to dynamically push context changes
to the Confidence object.

In both cases above, any context change triggers a new asynchronous `fetchAndActivate` and the flags in the
local cache are re-evaluated remotely according to the new context: until this background operation is complete,
flag values are returned to the application according to the old context's evaluation, and with `resolveReason = .stale`.
Copy link
Member Author

@fabriziodemaria fabriziodemaria Nov 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, I would add the following to the Spec:

putContext is an await-able function, which returns when the flag cache is ready and reflects the newly configured context. When using ConfidenceContextProducer, the context can change more dynamically and stale value are to be expected.



### Resolving feature flags
Once the Confidence instance is **activated**, you can access the flag values using the
Expand Down
Loading