TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: Do you have a guide on how to use feature flags?

8 点作者 victor_e大约 3 年前
I've seen lots of posts on HN saying that feature flags are a must use. How do you use them?

5 条评论

dabeeeenster大约 3 年前
We[4] have a few[1] guide[2] articles[3] in our docs which might give people some ideas on how they can be used.<p>[1] <a href="https:&#x2F;&#x2F;docs.flagsmith.com&#x2F;guides-and-examples&#x2F;mobile-app-versioning" rel="nofollow">https:&#x2F;&#x2F;docs.flagsmith.com&#x2F;guides-and-examples&#x2F;mobile-app-ve...</a><p>[2] <a href="https:&#x2F;&#x2F;docs.flagsmith.com&#x2F;guides-and-examples&#x2F;staged-feature-rollouts" rel="nofollow">https:&#x2F;&#x2F;docs.flagsmith.com&#x2F;guides-and-examples&#x2F;staged-featur...</a><p>[3] <a href="https:&#x2F;&#x2F;docs.flagsmith.com&#x2F;guides-and-examples&#x2F;testing-push-notifications" rel="nofollow">https:&#x2F;&#x2F;docs.flagsmith.com&#x2F;guides-and-examples&#x2F;testing-push-...</a><p>[4] <a href="https:&#x2F;&#x2F;github.com&#x2F;Flagsmith" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;Flagsmith</a>
jaredsohn大约 3 年前
The easiest way to do it is to create environment variables and check against them in code. This allows turning on &#x2F; off functionality globally. Systems like AWS and Heroku allow toggling them without redeploying.<p>You can also create features that apply to individual users or if enterprise then to all users in the customer. This can be done by creating some boolean fields in the database (using a single feature_flags json field is recommended because then you don&#x27;t have to change the schema every time a new feature flag is added.)<p>And then in code you check against the environment variable or against the user &#x2F; customer before running changed functionality via a simple if statement.
swah大约 3 年前
The idea is that for some particular new feature&#x2F;behaviour&#x2F;optimization your application has, instead of just coding it, code it in a way that can be disabled easily:<p>For example, I have some projects using using redux-saga, I&#x27;ll do something like:<p><pre><code> if (env.EnableSomeNewThing) { yield fork(saga1) } </code></pre> So this behavior can be enabled&#x2F;disabled using an env variable instead of commenting&#x2F;reverting code from Git. Of course this could also be more sophisticated: enable via configuration, enable for a sample of the users, or premium users...
efortis大约 3 年前
I export a boolean such as `hasFeatureX` and then delete it.<p><pre><code> if (hasFeatureX) doX() else … </code></pre> If it has to be more complex than that, I use a feature branch.
Valord大约 3 年前
Check out some of the blog posts from <a href="https:&#x2F;&#x2F;launchdarkly.com&#x2F;blog&#x2F;" rel="nofollow">https:&#x2F;&#x2F;launchdarkly.com&#x2F;blog&#x2F;</a>