Skip to content

Commit 1cfb232

Browse files
python rewrite (#489)
* python rewrite first draft * minor edits * final copy edits
1 parent 47de517 commit 1cfb232

File tree

5 files changed

+417
-305
lines changed

5 files changed

+417
-305
lines changed

docs/sdks/sdk-features/flag-types.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,61 @@ getJSONAssignment(...)
1313
```
1414

1515
The function names differ slightly according to naming conventions in the respective SDK languages. The function used to get the assignment must match the type of the feature flag. To get assignments for a JSON-typed feature flag being used as a dynamic config, for example, you would use `getJSONAssignment`, whereas incorrectly calling `getNumericAssignment` would return the default variation and no assignments would occur.
16+
17+
## Flag Types
18+
19+
### String Flags
20+
21+
String flags are the most common type of flags. They are useful for both A/B/n tests and advanced targeting use cases.
22+
23+
```javascript
24+
const variant = getStringAssignment(...);
25+
26+
if (variant === "version-a") {
27+
// ...
28+
} else if (variant === "version-b") {
29+
// ...
30+
} // ...
31+
```
32+
33+
### Boolean Flags
34+
35+
Boolean flags can help simple code for simple on/off toggles:
36+
37+
```javascript
38+
if getBooleanAssignment(...) {
39+
# ...
40+
} else {
41+
# ...
42+
}
43+
```
44+
45+
That prevents adding a third output. However, `True` can be ambiguous when the flag name names are unclear. For instance, `hide-or-delete-spam` or `no-collapse-price-breakdown`. We typically recommend sticking to strings that offer more explicit naming convention: `keep-and-hide-spam`, `delete-spam`, or `collapse-price-breakdown`, `expand-price-breakdown`, and `delete-price-breakdown`.
46+
47+
### Numeric and Integer Flags
48+
49+
Numeric and integer flags are useful when you want to modify a quantity: the number of product recommendations per page, the minimum spent for free delivery, etc. When someone edits the flag, it will remain a number. This helps prevent obvious configuration issues early.
50+
51+
```javascript
52+
const freeDeliveryThreshold = getIntegerAssignment(...);
53+
54+
if (purchaseAmount >= freeDeliveryThreshold) {
55+
// apply free delivery
56+
}
57+
```
58+
59+
### JSON Flags
60+
61+
For advanced configuration use cases, consider using JSON flags. This allows us to include structured information, say the text of a marketing copy for a promotional campaign and the address of a hero image. Thanks to this pattern, one developer can configure a very simple landing page; with that in place, whoever has access to the feature flag configuration can decide and change what copy to show to users throughout a promotional period, almost instantly and without them having to release new code.
62+
63+
```javascript
64+
const campaignJson = getJSONAssignment(...);
65+
if (campaignJson !== null) {
66+
campaign.hero = true;
67+
campaign.heroImage = campaignJson.heroImage;
68+
campaign.heroTitle = campaignJson.heroTitle || "";
69+
campaign.heroDescription = campaignJson.heroDescription || "";
70+
}
71+
```
72+
73+
Assuming your service can be configured with many input parameters, that flag type enables very flexible configuration changes.

0 commit comments

Comments
 (0)