UNPKG

1.27 kBMarkdownView Raw
1# Features
2
3[RFC](https://github.com/salesforce/lwc-rfcs/blob/master/text/0111-feature-flags.md)
4
5## Compile-time flags
6
7## Runtime flags
8
9Runtime flags can be enabled or disabled by setting a boolean value for that
10flag in `globalThis.LWC_config.features`. If the flag is not explicitly
11configured, the feature is disabled by default. This configuration object
12must appear before `@lwc/engine` is initialized and should be defined at the
13application layer.
14
15### Limitations
16
17#### Must be all uppercase
18
19```
20// Does not work
21if (enableFoo) {
22 ...
23}
24
25// Does work
26if (ENABLE_FOO) {
27 ...
28}
29```
30
31#### Only works with if-statements
32
33```
34// Does not work
35const foo = ENABLE_FOO ? 1 : 2;
36
37// Does work
38let foo;
39if (ENABLE_FOO) {
40 foo = 1;
41} else {
42 foo = 2;
43}
44```
45
46#### Only works with identifiers
47
48```
49// Does not work
50if (isTrue(ENABLE_AWESOME_FEATURE)) {
51 // awesome feature
52}
53
54// Does work
55if (ENABLE_AWESOME_FEATURE) {
56 // awesome feature
57}
58```
59
60#### Initialization code cannot be tested
61
62Toggling the value of `ENABLE_FOO` during a test will not change the return
63value of `getFooValue`.
64
65```
66import { ENABLE_FOO } from '@lwc/features';
67
68let foo;
69if (ENABLE_FOO) {
70 foo = 1;
71} else {
72 foo = 2;
73}
74
75function getFooValue() {
76 return foo;
77}
78```