UNPKG

5.38 kBPlain TextView Raw
1/**
2 * ## Canary Features
3 *
4 * EmberData allows users to test features that are implemented but not yet
5 * available even in canary.
6 *
7 * Typically these features represent work that might introduce a new concept,
8 * new API, change an API, or risk an unintended change in behavior to consuming
9 * applications.
10 *
11 * Such features have their implementations guarded by a "feature flag", and the
12 * flag is only activated once the core-data team is prepared to ship the work
13 * in a canary release.
14 *
15 * ### Installing Canary
16 *
17 * To test a feature you MUST be using a canary build. Canary builds are published
18 * to `npm` and can be installed using a precise tag (such as `ember-data@3.16.0-alpha.1`)
19 * or by installing the latest dist-tag published to the `canary` channel.
20 *
21 * *Using `npm` to install the latest canary*
22 *
23 * ```cli
24 * npm install --save-dev ember-data@canary
25 * ```
26 *
27 * *Using `yarn` to install the latest canary*
28 *
29 * ```cli
30 * yarn add ember-data@canary
31 * ```
32 *
33 * ### Activating a Canary Feature
34 *
35 * Once you have installed canary, feature-flags can be activated at build-time by an environment
36 * variable or at runtime using `window.EmberDataENV`.
37 *
38 * The "off" branch of feature-flagged code is always stripped from production builds, so you
39 * MUST use the build-time environment variable to activate a flag if testing production.
40 *
41 * The list of available feature-flags is located [here](https://github.com/emberjs/data/tree/master/packages/canary-features/addon/default-features.ts "List of EmberData FeatureFlags")
42 *
43 * #### Runtime Configuration
44 *
45 * To configure feature-flags at runtime you will want to configure `window.EmberDataENV = {}` appropriately.
46 * You should add this global property in your app prior to your application booting. At the top of
47 * your `app.js` file is a convenient location, as is within ` index.html` as a script running prior
48 * to loading any other scripts.
49 *
50 * *Example activating a single feature flags*
51 *
52 * ```js
53 * window.EmberDataENV = {
54 * FEATURES: {
55 * RECORD_DATA_ERRORS: true,
56 * }
57 * }
58 * ```
59 *
60 * *Example activating multiple feature flags*
61 *
62 * ```js
63 * window.EmberDataENV = {
64 * FEATURES: {
65 * RECORD_DATA_ERRORS: true,
66 * RECORD_DATA_STATE: true,
67 * }
68 * }
69 * ```
70 *
71 * *Example activating all feature flags*
72 *
73 * ```js
74 * window.EmberDataENV = {
75 * ENABLE_OPTIONAL_FEATURES: true
76 * }
77 * ```
78 *
79 * #### Build Time Configuration
80 *
81 * *Example activating a single feature flags*
82 *
83 * ```js
84 * EMBER_DATA_FEATURE_OVERRIDE=REQUEST_SERVICE ember build
85 * ```
86 *
87 * *Example activating multiple feature flags*
88 *
89 * ```js
90 * EMBER_DATA_FEATURE_OVERRIDE=REQUEST_SERVICE,CUSTOM_MODEL_CLASS ember build
91 * ```
92 *
93 * *Example activating all feature flags*
94 *
95 * ```js
96 * EMBER_DATA_FEATURE_OVERRIDE=ENABLE_ALL_OPTIONAL ember build
97 * ```
98 *
99 * ### Preparing an Addon to use a Canary Feature
100 *
101 * For most addons and most features simple version detection should be
102 * enough. Using the provided version compatibility helpers from
103 * [ember-compatibility-helpers](https://github.com/pzuraq/ember-compatibility-helpers)
104 * the following can be done:
105 *
106 * ```js
107 * if (gte('@ember-data/store', '3.12.0')) {
108 *
109 * } else {
110 *
111 * }
112 * ```
113 *
114 * For addons needing more advanced detection [babel-plugin-debug-macros](https://github.com/ember-cli/babel-plugin-debug-macros)
115 * can be leveraged to provide code-stripping based on feature presence. For example in your addon's `index.js`:
116 *
117 * ```js
118 * function debugMacros(features) {
119 * let plugins = [
120 * [
121 * require.resolve('babel-plugin-debug-macros'),
122 * {
123 * flags: [
124 * {
125 * source: '<addon-name>/feature-flags',
126 * flags: features,
127 * },
128 * ],
129 * },
130 * '<addon-name>/canary-features-stripping',
131 * ],
132 * ];
133 *
134 * return plugins;
135 * }
136 *
137 * module.exports = {
138 * name: '<addon-name>',
139 *
140 * init() {
141 * this._super.init.apply(this, arguments);
142 *
143 * let features;
144 * try {
145 * features = this.project.require('@ember-data/private-build-infra/src/features')();
146 * } catch (e) {
147 * features = { CUSTOM_MODEL_CLASS: false };
148 * }
149 *
150 * this.options = this.options || {};
151 * this.options.babel = this.options.babel || {};
152 * // this ensures that the same `@ember-data/canary-features` processing that the various
153 * // ember-data addons do is done for this addon
154 * this.options.babel.plugins = [...debugMacros(features)];
155 * }
156 * }
157 * ```
158 *
159 * @module @ember-data/canary-features
160 * @main @ember-data/canary-features
161 */
162/*
163 This list of features is used both at build time (by `@ember-data/private-build-infra`)
164 and at runtime (by `@ember-data/canary-features`).
165
166 The valid values are:
167
168 - true - The feature is enabled at all times, and cannot be disabled.
169 - false - The feature is disabled at all times, and cannot be enabled.
170 - null - The feature is disabled by default, but can be enabled at runtime via `EmberDataENV`.
171*/
172export default {
173 SAMPLE_FEATURE_FLAG: null,
174 RECORD_DATA_ERRORS: null,
175 RECORD_DATA_STATE: null,
176 IDENTIFIERS: true,
177 REQUEST_SERVICE: null,
178 CUSTOM_MODEL_CLASS: null,
179 FULL_LINKS_ON_RELATIONSHIPS: true,
180 RECORD_ARRAY_MANAGER_IDENTIFIERS: true,
181 REMOVE_RECORD_ARRAY_MANAGER_LEGACY_COMPAT: null,
182};