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

feat: wrap vercel flags #903

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

feat: wrap vercel flags #903

wants to merge 4 commits into from

Conversation

ajwootto
Copy link
Contributor

@ajwootto ajwootto commented Jul 23, 2024

  • create a helper in Next SDK that wraps the Vercel "flag" function to make it "feature /variation" aware
  • when you call the returned wrapped function with a variable key and default value, it figures out from the main config which feature that variable belongs to. It then calls the Vercel "flag" function using the feature as the "key" and obtaining a variation id for that feature
  • it also provides "options" for the toolbar which are the list of variations in the feature
  • this allows someone using the toolbar to select an override for a feature and its variation, which is then used to alter the values of all the variables in that feature, but the code can continue to use variable keys for evaluation

Copy link

vercel bot commented Jul 23, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
js-sdks-web-elements ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 24, 2024 8:07pm
js-sdks-with-provider ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 24, 2024 8:07pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
js-sdks-next-js-page-router ⬜️ Ignored (Inspect) Jul 24, 2024 8:07pm

@@ -20,3 +22,8 @@ export const {
},
options: { enableStreaming: false },
})

export const getFlag = setupDevCycleVercelFlagHelper({
Copy link
Member

Choose a reason for hiding this comment

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

Why as a separate import and not a part of setupDevCycle()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because it depends on the @vercel/flags package which I wanted to make an optional dependency. So the idea is that if you want to use it with Vercel, you install their flags package and import this helper from @devcycle/nextjs-sdk/vercel where it expects the package to be available.


const getFlag = flag<string | null>({
key: featureForVariable.key,
defaultValue: null,
Copy link
Member

Choose a reason for hiding this comment

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

why no default here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because this is serving the variation of the feature that should be used to obtain the flag value. The default for that should be "no variation" which is interpreted by the code further down as "use the variable's default"

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

Successfully merging this pull request may close these issues.

2 participants