4
4
* found in the LICENSE file.
5
5
*/
6
6
7
- /*
8
- `<wpt-flags>` is a component for checking wpt.fyi feature flags.
9
- */
7
+ /**
8
+ * wpt-flags.js defines components for checking wpt.fyi feature flags, which
9
+ * are boolean switches primarily used to enable or disable features.
10
+ *
11
+ * Feature flags in wpt.fyi use two different layers of storage. Firstly, the
12
+ * default value for the flag (if any) is recorded in AppEngine DataStore and
13
+ * provided to the frontend via the `WPTEnvironmentFlags` dynamic component. If
14
+ * no default exists, it is considered to be false. This layer is often
15
+ * referred to as 'admin flags', and can be modified from the wpt.fyi UI by
16
+ * users with the relevant permissions.
17
+ *
18
+ * The other layer of storage for feature flags is the browser's localStorage,
19
+ * which is used to let users override the default value. Again by default (and
20
+ * assuming no underlying admin value) a feature flag is assumed to be false if
21
+ * it has no value.
22
+ *
23
+ * Feature flags are split into client-side features, which only impact the
24
+ * wpt.fyi UI, and server-side features, which affect the backend too.
25
+ * Server-side features only care about the backing datastore storage layer,
26
+ * and do not interact with localStorage.
27
+ */
28
+
10
29
import '../node_modules/@polymer/paper-checkbox/paper-checkbox.js' ;
11
30
import '../node_modules/@polymer/paper-item/paper-item.js' ;
12
31
import { html , PolymerElement } from '../node_modules/@polymer/polymer/polymer-element.js' ;
@@ -84,6 +103,9 @@ const makeFeatureProperties = function(target, features, readOnly, useLocalStora
84
103
}
85
104
} ;
86
105
106
+ // FlagsClass defines a shared superclass for reading feature flags. It assumes
107
+ // that it will be part of a custom element class chain, as it relies on
108
+ // Polymer's 'properties' concept to expose the feature flag values.
87
109
wpt . FlagsClass = ( superClass , readOnly , useLocalStorage ) => class extends superClass {
88
110
static get is ( ) {
89
111
return 'wpt-flags' ;
@@ -108,8 +130,24 @@ wpt.FlagsClass = (superClass, readOnly, useLocalStorage) => class extends superC
108
130
}
109
131
} ;
110
132
133
+ // WPTFlags is a 'reader' class function for feature flags. To use it, a custom
134
+ // element should include WPTFlags in its extension chain and then access flag
135
+ // values via 'this', e.g.:
136
+ //
137
+ // class MyCustomElement extends WPTFlags(PolymerElement) {
138
+ // foo() {
139
+ // const featureEnabled = this.myFeatureFlag;
140
+ // ...
141
+ // }
142
+ // }
111
143
const WPTFlags = ( superClass ) => wpt . FlagsClass ( superClass , /*readOnly*/ true , /*useLocalStorage*/ true ) ;
112
144
145
+ // FlagsEditorClass is a 'writer' class function for feature flags. It allows
146
+ // both reading values (identically to WPTFlags) and writing to them.
147
+ //
148
+ // The environmentFlags argument controls whether the class will read/write
149
+ // from localStorage (if environmentFlags is false) or the backing datastore
150
+ // (if environmentFlags is true).
113
151
const FlagsEditorClass = ( environmentFlags ) =>
114
152
class extends wpt . FlagsClass ( PolymerElement , /*readOnly*/ false , /*useLocalStorage*/ ! environmentFlags ) {
115
153
ready ( ) {
@@ -155,6 +193,9 @@ const FlagsEditorClass = (environmentFlags) =>
155
193
}
156
194
} ;
157
195
196
+ // WPTFlagsEditor is a Polymer custom element for modifying client-side feature
197
+ // flags. It presents a set of checkboxes that the user can select/unselect to
198
+ // override the feature flag value at the localStorage layer.
158
199
class WPTFlagsEditor extends FlagsEditorClass ( /*environmentFlags*/ false ) {
159
200
static get template ( ) {
160
201
return html `
@@ -283,6 +324,10 @@ class WPTFlagsEditor extends FlagsEditorClass(/*environmentFlags*/ false) {
283
324
}
284
325
window . customElements . define ( WPTFlagsEditor . is , WPTFlagsEditor ) ;
285
326
327
+ // WPTEnvironmentFlagsEditor is a Polymer custom element for modifying the
328
+ // default values for both client-side and server-side feature flags. It
329
+ // presents a set of checkboxes that an authorized user can select/unselect to
330
+ // override the feature flag value at the datastore layer.
286
331
class WPTEnvironmentFlagsEditor extends FlagsEditorClass ( /*environmentFlags*/ true ) {
287
332
static get template ( ) {
288
333
return html `
0 commit comments