10000 What is the difference in calling `exampleFlag()` and `exampleFlag.decide()` in flags/next? · Issue #124 · vercel/flags · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

What is the difference in calling exampleFlag() and exampleFlag.decide() in flags/next? #124

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

Open
kcrwfrd opened this issue Apr 28, 2025 · 2 comments
Assignees
Labels

Comments

@kcrwfrd
Copy link
kcrwfrd commented Apr 28, 2025

The docs don't offer any explanation here.

The quickstart guides and examples use exampleFlag() but this isn't documented in the API reference, and neither are the flag instance methods like exampleFlag.decide()

@AAorris
Copy link
Contributor
AAorris commented Apr 28, 2025

Hi @kcrwfrd, it's a good callout that they may seem identical at first glance and we lack docs here.

You have probably noticed that the documentation always calls flags and does not propose calling the decide function yourself.

In the simplest case, decide() is just an asynchronous function, and that's what you'll see in the hello world flags.

Why you should always call exampleFlag():

Function parameters

The call signature of a flag is either no arguments, or precompute arguments.

Decide functions can accept cookies and headers among other things, and the Flags SDK does the work to retrieve them based on the framework you're using, making functions that use these more portable across frameworks (more relevant to adapters, below)

Adapter support

The declaration of a flag either has decide, or adapter (and optionally identify). The flags SDK knows how to handle these more complex declarations and handles it automatically.

Overrides

Flags SDK will check for overrides from the Vercel Toolbar when calling the flag. Calling decide will mean that overrides aren't respected.


I wonder if that satisfies your curiosity and is worth explaining on https://flags-sdk.dev?

@kcrwfrd
Copy link
Author
kcrwfrd commented Apr 28, 2025

@AAorris thank you very much, this is exactly the context I was looking for.

I think it would be very helpful to include this information in the docs, and to document the Flag type in the API reference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants
0