ember-source 7.2.0-beta.1 → 7.3.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/build-metadata.json +3 -3
  2. package/dist/dev/packages/@ember/-internals/deprecations/index.js +10 -0
  3. package/dist/dev/packages/@ember/-internals/glimmer/index.js +7 -7
  4. package/dist/dev/packages/@ember/-internals/metal/index.js +8 -8
  5. package/dist/dev/packages/@ember/-internals/routing/index.js +1 -1
  6. package/dist/dev/packages/@ember/-internals/runtime/lib/mixins/-proxy.js +3 -3
  7. package/dist/dev/packages/@ember/-internals/runtime/lib/mixins/comparable.js +5 -0
  8. package/dist/dev/packages/@ember/-internals/runtime/lib/mixins/target_action_support.js +1 -1
  9. package/dist/dev/packages/@ember/-internals/views/lib/system/event_dispatcher.js +1 -1
  10. package/dist/dev/packages/@ember/-internals/views/lib/views/core_view.js +1 -1
  11. package/dist/dev/packages/@ember/application/index.js +2 -2
  12. package/dist/dev/packages/@ember/application/instance.js +22 -2
  13. package/dist/dev/packages/@ember/array/index.js +3 -3
  14. package/dist/dev/packages/@ember/array/proxy.js +3 -3
  15. package/dist/dev/packages/@ember/component/helper.js +321 -1
  16. package/dist/dev/packages/@ember/component/index.js +3 -3
  17. package/dist/dev/packages/@ember/controller/index.js +2 -2
  18. package/dist/dev/packages/@ember/engine/index.js +3 -3
  19. package/dist/dev/packages/@ember/object/computed.js +2 -2
  20. package/dist/dev/packages/@ember/object/core.js +2 -2
  21. package/dist/dev/packages/@ember/object/index.js +4 -4
  22. package/dist/dev/packages/@ember/object/lib/computed/computed_macros.js +3 -3
  23. package/dist/dev/packages/@ember/object/lib/computed/reduce_computed_macros.js +1 -1
  24. package/dist/dev/packages/@ember/object/mixin.js +1 -1
  25. package/dist/dev/packages/@ember/object/observable.js +3 -3
  26. package/dist/dev/packages/@ember/object/promise-proxy-mixin.js +2 -2
  27. package/dist/dev/packages/@ember/renderer/index.js +1 -1
  28. package/dist/dev/packages/@ember/routing/-internals.js +1 -1
  29. package/dist/dev/packages/@ember/routing/lib/routing-service.js +0 -1
  30. package/dist/dev/packages/@ember/routing/lib/utils.js +1 -1
  31. package/dist/dev/packages/@ember/routing/route.js +4 -4
  32. package/dist/dev/packages/@ember/routing/router-service.js +0 -1
  33. package/dist/dev/packages/@ember/routing/router.js +3 -3
  34. package/dist/dev/packages/@ember/service/index.js +1 -1
  35. package/dist/dev/packages/@ember/utils/lib/compare.js +5 -2
  36. package/dist/dev/packages/@glimmer/node/index.js +2 -2
  37. package/dist/dev/packages/@glimmer/runtime/index.js +3 -3
  38. package/dist/dev/packages/@glimmer/tracking/index.js +1 -1
  39. package/dist/dev/packages/@glimmer/validator/index.js +1 -1
  40. package/dist/dev/packages/ember/version.js +1 -1
  41. package/dist/dev/packages/router_js/index.js +2 -2
  42. package/dist/dev/packages/shared-chunks/{alias-DpqL1qx6.js → alias-CT_thCad.js} +2 -2
  43. package/dist/dev/packages/shared-chunks/{api-C0PAtEgQ.js → api-Dz70AUL_.js} +6 -4
  44. package/dist/dev/packages/shared-chunks/{array-CVEnNWng.js → array-DvaweI_T.js} +1 -1
  45. package/dist/dev/packages/shared-chunks/{computed-BPCtuOxQ.js → computed-DGxbeUbf.js} +1 -6
  46. package/dist/dev/packages/shared-chunks/{curly-Ei5G8jhk.js → curly-DGUCLOud.js} +4 -5
  47. package/dist/dev/packages/shared-chunks/curly-brand-B_F79Dep.js +12 -0
  48. package/dist/dev/packages/shared-chunks/helper-brand-C9_8vvOf.js +12 -0
  49. package/dist/dev/packages/shared-chunks/{index-B3pPx1fL.js → index-D1AjYv31.js} +618 -1575
  50. package/dist/dev/packages/shared-chunks/{injected_property-CbBLr5jt.js → injected_property-DbXd6Gax.js} +1 -1
  51. package/dist/dev/packages/shared-chunks/outlet-CHFL7tun.js +135 -0
  52. package/dist/dev/packages/shared-chunks/{property_set-qCUylPEK.js → property_set-CVlVgdor.js} +1 -1
  53. package/dist/dev/packages/shared-chunks/{rehydrate-builder-C6k1XhET.js → rehydrate-builder-CsnkZkur.js} +1 -1
  54. package/dist/dev/packages/shared-chunks/{render-87_sKZ_k.js → render-CtH73XOv.js} +10 -5
  55. package/dist/dev/packages/shared-chunks/{serialize-builder-BlxBjwO-.js → serialize-builder-D1oAeiyl.js} +1 -1
  56. package/dist/dev/packages/shared-chunks/{set_properties-C4TSebH6.js → set_properties-CEUT_EJn.js} +2 -2
  57. package/dist/dev/packages/shared-chunks/setup-registry-DQ3c4Juo.js +951 -0
  58. package/dist/dev/packages/shared-chunks/{textarea-C4lYkaHj.js → textarea-DEvw4ezm.js} +1 -1
  59. package/dist/dev/packages/shared-chunks/tracked-57EW14Ny.js +253 -0
  60. package/dist/dev/packages/shared-chunks/tracked-value-DhyJmrhG.js +115 -0
  61. package/dist/dev/packages/shared-chunks/{unrecognized-url-error-BJHjL30Q.js → unrecognized-url-error-B8loxkay.js} +1 -1
  62. package/dist/prod/packages/@ember/-internals/deprecations/index.js +10 -0
  63. package/dist/prod/packages/@ember/-internals/glimmer/index.js +7 -7
  64. package/dist/prod/packages/@ember/-internals/metal/index.js +8 -8
  65. package/dist/prod/packages/@ember/-internals/routing/index.js +1 -1
  66. package/dist/prod/packages/@ember/-internals/runtime/lib/mixins/-proxy.js +3 -3
  67. package/dist/prod/packages/@ember/-internals/runtime/lib/mixins/comparable.js +5 -0
  68. package/dist/prod/packages/@ember/-internals/runtime/lib/mixins/target_action_support.js +1 -1
  69. package/dist/prod/packages/@ember/-internals/views/lib/system/event_dispatcher.js +1 -1
  70. package/dist/prod/packages/@ember/-internals/views/lib/views/core_view.js +1 -1
  71. package/dist/prod/packages/@ember/application/index.js +2 -2
  72. package/dist/prod/packages/@ember/application/instance.js +18 -3
  73. package/dist/prod/packages/@ember/array/index.js +3 -3
  74. package/dist/prod/packages/@ember/array/proxy.js +3 -3
  75. package/dist/prod/packages/@ember/component/helper.js +305 -1
  76. package/dist/prod/packages/@ember/component/index.js +3 -3
  77. package/dist/prod/packages/@ember/controller/index.js +2 -2
  78. package/dist/prod/packages/@ember/engine/index.js +3 -3
  79. package/dist/prod/packages/@ember/object/computed.js +2 -2
  80. package/dist/prod/packages/@ember/object/index.js +4 -4
  81. package/dist/prod/packages/@ember/object/lib/computed/computed_macros.js +3 -3
  82. package/dist/prod/packages/@ember/object/lib/computed/reduce_computed_macros.js +1 -1
  83. package/dist/prod/packages/@ember/object/mixin.js +1 -1
  84. package/dist/prod/packages/@ember/object/observable.js +3 -3
  85. package/dist/prod/packages/@ember/object/promise-proxy-mixin.js +2 -2
  86. package/dist/prod/packages/@ember/renderer/index.js +1 -1
  87. package/dist/prod/packages/@ember/routing/lib/routing-service.js +0 -1
  88. package/dist/prod/packages/@ember/routing/lib/utils.js +1 -1
  89. package/dist/prod/packages/@ember/routing/route.js +4 -4
  90. package/dist/prod/packages/@ember/routing/router-service.js +0 -1
  91. package/dist/prod/packages/@ember/routing/router.js +3 -3
  92. package/dist/prod/packages/@ember/service/index.js +1 -1
  93. package/dist/prod/packages/@ember/utils/lib/compare.js +5 -2
  94. package/dist/prod/packages/@glimmer/node/index.js +2 -2
  95. package/dist/prod/packages/@glimmer/runtime/index.js +3 -3
  96. package/dist/prod/packages/@glimmer/tracking/index.js +1 -1
  97. package/dist/prod/packages/@glimmer/validator/index.js +1 -1
  98. package/dist/prod/packages/ember/version.js +1 -1
  99. package/dist/prod/packages/router_js/index.js +2 -2
  100. package/dist/prod/packages/shared-chunks/{alias-Bod6qdNp.js → alias-CHHuE0LE.js} +2 -2
  101. package/dist/prod/packages/shared-chunks/{api-CQexacBn.js → api-DzOa0Acr.js} +6 -4
  102. package/dist/prod/packages/shared-chunks/{array-BzReKMeW.js → array-CnXdmzOG.js} +1 -1
  103. package/dist/prod/packages/shared-chunks/{computed-DtIStxvq.js → computed-BNdMwGhH.js} +1 -6
  104. package/dist/prod/packages/shared-chunks/{curly-IY06zACp.js → curly-a6DP7r87.js} +4 -5
  105. package/dist/prod/packages/shared-chunks/curly-brand-B_F79Dep.js +12 -0
  106. package/dist/prod/packages/shared-chunks/helper-brand-C9_8vvOf.js +12 -0
  107. package/dist/prod/packages/shared-chunks/{index-CslMfEpb.js → index-CvQQ6l11.js} +548 -1451
  108. package/dist/prod/packages/shared-chunks/{injected_property-Y-FadDej.js → injected_property-DqQ0XV7k.js} +1 -1
  109. package/dist/prod/packages/shared-chunks/outlet--lIm3q7t.js +132 -0
  110. package/dist/prod/packages/shared-chunks/{property_set-BaQJdVfS.js → property_set-CkLe4ht8.js} +1 -1
  111. package/dist/prod/packages/shared-chunks/{rehydrate-builder-Blt1x9MP.js → rehydrate-builder-n_8RCUj9.js} +1 -1
  112. package/dist/prod/packages/shared-chunks/{render-Dx7lr1hR.js → render-Bf7GviCY.js} +10 -5
  113. package/dist/prod/packages/shared-chunks/{serialize-builder-BvAXYHTr.js → serialize-builder-CsG9WHVw.js} +1 -1
  114. package/dist/prod/packages/shared-chunks/{set_properties-Qxhw4qzw.js → set_properties-Cs3rVemD.js} +2 -2
  115. package/dist/prod/packages/shared-chunks/setup-registry-kOGgOucf.js +886 -0
  116. package/dist/prod/packages/shared-chunks/{textarea-DOmZ1x0E.js → textarea-DMmdvgk2.js} +1 -1
  117. package/dist/prod/packages/shared-chunks/tracked-DvOpYI0o.js +235 -0
  118. package/dist/prod/packages/shared-chunks/tracked-value-CR6kx-73.js +115 -0
  119. package/dist/prod/packages/shared-chunks/{unrecognized-url-error-EgNrnFu_.js → unrecognized-url-error-jjQ-FqKB.js} +1 -1
  120. package/docs/data.json +426 -222
  121. package/package.json +6 -6
  122. package/types/stable/@ember/-internals/deprecations/index.d.ts +6 -0
  123. package/types/stable/@ember/-internals/glimmer/lib/base-renderer.d.ts +150 -0
  124. package/types/stable/@ember/-internals/glimmer/lib/component-managers/curly-brand.d.ts +10 -0
  125. package/types/stable/@ember/-internals/glimmer/lib/component-managers/curly.d.ts +3 -2
  126. package/types/stable/@ember/-internals/glimmer/lib/glimmer-tracking-docs.d.ts +68 -0
  127. package/types/stable/@ember/-internals/glimmer/lib/helper-brand.d.ts +10 -0
  128. package/types/stable/@ember/-internals/glimmer/lib/helper.d.ts +4 -6
  129. package/types/stable/@ember/-internals/glimmer/lib/renderer.d.ts +7 -154
  130. package/types/stable/@ember/-internals/glimmer/lib/router-resolver.d.ts +17 -0
  131. package/types/stable/@ember/-internals/metal/lib/tracked.d.ts +53 -6
  132. package/types/stable/@ember/renderer/index.d.ts +2 -2
  133. package/types/stable/@glimmer/tracking/index.d.ts +70 -1
  134. package/types/stable/@glimmer/validator/index.d.ts +1 -0
  135. package/types/stable/@glimmer/validator/lib/tracked-value.d.ts +58 -0
  136. package/types/stable/index.d.ts +591 -586
  137. package/dist/dev/packages/shared-chunks/helper-DIj85_-f.js +0 -326
  138. package/dist/dev/packages/shared-chunks/setup-registry-9DCmHTFF.js +0 -77
  139. package/dist/dev/packages/shared-chunks/tracked-DEyf0T_X.js +0 -148
  140. package/dist/dev/packages/shared-chunks/tracked-data-DgqqRdYO.js +0 -31
  141. package/dist/prod/packages/shared-chunks/helper-DkXiTBjc.js +0 -310
  142. package/dist/prod/packages/shared-chunks/setup-registry-U-6VaNQG.js +0 -74
  143. package/dist/prod/packages/shared-chunks/tracked-B9380JtC.js +0 -132
  144. package/dist/prod/packages/shared-chunks/tracked-data-CHq42QHb.js +0 -31
@@ -6,7 +6,7 @@ import { on } from '../@ember/modifier/on.js';
6
6
  import { t as templateFactory } from './index-Bf53M8eS.js';
7
7
  import { I as InternalComponent, o as opaquify } from './internal-BQ7zHrqS.js';
8
8
  import { d as decorateFieldV2, i as initializeDeferredDecorator, a as decorateMethodV2 } from './runtime-CYyqkz5q-BOdRhmsS.js';
9
- import { t as tracked } from './tracked-B9380JtC.js';
9
+ import { t as tracked } from './tracked-DvOpYI0o.js';
10
10
 
11
11
  const InputTemplate = templateFactory(
12
12
  /*
@@ -0,0 +1,235 @@
1
+ import { meta } from '../@ember/-internals/meta/lib/meta.js';
2
+ import { isEmberArray } from '../@ember/array/-internals.js';
3
+ import { c as consumeTag, u as untrack } from './cache-CofLhaS4.js';
4
+ import { d as dirtyTagFor, t as tagFor } from './meta-BJtIZDir.js';
5
+ import { t as trackedValue, a as trackedData } from './tracked-value-CR6kx-73.js';
6
+ import { C as CHAIN_PASS_THROUGH, S as SELF_TAG } from './chain-tags-B2J7DsxO.js';
7
+ import { i as isElementDescriptor, C as COMPUTED_SETTERS, s as setClassicDecorator } from './decorator-9ikVwsjY.js';
8
+
9
+ /**
10
+ @decorator
11
+ @private
12
+
13
+ Marks a property as tracked.
14
+
15
+ By default, a component's properties are expected to be static,
16
+ meaning you are not able to update them and have the template update accordingly.
17
+ Marking a property as tracked means that when that property changes,
18
+ a rerender of the component is scheduled so the template is kept up to date.
19
+
20
+ There are two usages for the `@tracked` decorator, shown below.
21
+
22
+ @example No dependencies
23
+
24
+ If you don't pass an argument to `@tracked`, only changes to that property
25
+ will be tracked:
26
+
27
+ ```typescript
28
+ import Component from '@glimmer/component';
29
+ import { tracked } from '@glimmer/tracking';
30
+
31
+ export default class MyComponent extends Component {
32
+ @tracked
33
+ remainingApples = 10
34
+ }
35
+ ```
36
+
37
+ When something changes the component's `remainingApples` property, the rerender
38
+ will be scheduled.
39
+
40
+ @example Dependents
41
+
42
+ In the case that you have a computed property that depends other
43
+ properties, you want to track both so that when one of the
44
+ dependents change, a rerender is scheduled.
45
+
46
+ In the following example we have two properties,
47
+ `eatenApples`, and `remainingApples`.
48
+
49
+ ```typescript
50
+ import Component from '@glimmer/component';
51
+ import { tracked } from '@glimmer/tracking';
52
+
53
+ const totalApples = 100;
54
+
55
+ export default class MyComponent extends Component {
56
+ @tracked
57
+ eatenApples = 0
58
+
59
+ get remainingApples() {
60
+ return totalApples - this.eatenApples;
61
+ }
62
+
63
+ increment() {
64
+ this.eatenApples = this.eatenApples + 1;
65
+ }
66
+ }
67
+ ```
68
+
69
+ @param dependencies Optional dependents to be tracked.
70
+ */
71
+ /**
72
+ * Reactivity options for the standalone `tracked(value, options)` form.
73
+ *
74
+ * - `equals` decides whether writing a value notifies consumers; it defaults to
75
+ * `Object.is`.
76
+ * - `description` is used in development for debugging.
77
+ *
78
+ * `equals` is a function-typed property (rather than method syntax) on purpose:
79
+ * this keeps its parameters checked strictly, so passing an `equals` typed for
80
+ * the wrong value type is a type error instead of being silently accepted.
81
+ */
82
+
83
+ /**
84
+ * Options for `tracked` used as a decorator, or as a field on a *classic* class
85
+ * (`EmberObject.extend({ foo: tracked({ value }) })`).
86
+ *
87
+ * All properties are optional because this single shape backs several usages:
88
+ * classic-field defaults (`tracked({ value })` / `tracked({ initializer })`) and
89
+ * options-only native decorators (`@tracked({ equals })`). The mutually
90
+ * exclusive combinations (e.g. both `value` and `initializer`) and the
91
+ * classic-only restriction on `value`/`initializer` are enforced at runtime via
92
+ * assertions rather than in the type, matching the runtime `isDecoratorOptions`
93
+ * check that accepts any object composed of these keys.
94
+ *
95
+ * - `value` / `initializer` supply a default value and are only valid on classic
96
+ * classes; native classes use class field initializers instead.
97
+ * - `equals` / `description` configure reactivity, mirroring
98
+ * {@link TrackedValueOptions}.
99
+ */
100
+
101
+ /**
102
+ * `tracked` as a decorator factory: `@tracked({ equals })`, or on classic
103
+ * classes `tracked({ value })` / `tracked({ initializer })`.
104
+ */
105
+
106
+ /**
107
+ * `tracked` as a bare decorator: `@tracked foo = 1`.
108
+ */
109
+
110
+ /**
111
+ * `tracked` as a standalone reactive value, usable outside of classes:
112
+ * `const count = tracked(0)`.
113
+ */
114
+
115
+ function tracked(...args) {
116
+ if (isElementDescriptor(args)) {
117
+ /*
118
+ Native-decorator form. The runtime invokes us with `(target, key, desc)`
119
+ and consumes the returned `DecoratorPropertyDescriptor`. The public API is
120
+ the decorated field itself — reading it consumes, assigning it dirties.
121
+ ```js
122
+ class Counter {
123
+ @tracked count = 0;
124
+ }
125
+ ```
126
+ */
127
+ return descriptorForField(args);
128
+ }
129
+ if (args.length === 0 || args.length === 1 && isDecoratorOptions(args[0])) {
130
+ /*
131
+ Decorator-factory / classic-field form. Returns an
132
+ `ExtendedMethodDecorator`. The public API is the resulting property on
133
+ instances (get/set), with any default supplied by `value`/`initializer`.
134
+ ```js
135
+ class Counter {
136
+ @tracked({ equals: (a, b) => a === b }) count = 0;
137
+ }
138
+ const Person = EmberObject.extend({
139
+ name: tracked({ value: 'Zoey' }),
140
+ });
141
+ ```
142
+ */
143
+ return makeTrackedDecorator(args[0]);
144
+ }
145
+ let [initialValue, options] = args;
146
+ /*
147
+ Standalone-value form. Returns a `TrackedValue` usable outside of classes.
148
+ ```js
149
+ const count = tracked(0);
150
+ count.value; // read (consumes), `Object.is`-based equality
151
+ count.value = 1; // write (dirties)
152
+ count.get(); // function shorthand for reading
153
+ count.set(2); // returns `true` if the value changed
154
+ count.update((n) => n + 1); // write from current, without consuming
155
+ count.freeze(); // prevent further writes
156
+ ```
157
+ */
158
+ return trackedValue(initialValue, options);
159
+ }
160
+ const DECORATOR_OPTION_KEYS = ['value', 'initializer', 'equals', 'description'];
161
+ function isDecoratorOptions(value) {
162
+ if (typeof value !== 'object' || value === null) {
163
+ return false;
164
+ }
165
+ let proto = Object.getPrototypeOf(value);
166
+ if (proto !== Object.prototype && proto !== null) {
167
+ return false;
168
+ }
169
+ return Object.keys(value).every(key => DECORATOR_OPTION_KEYS.includes(key));
170
+ }
171
+ function makeTrackedDecorator(propertyDesc) {
172
+ let initializer = propertyDesc ? propertyDesc.initializer : undefined;
173
+ let value = propertyDesc ? propertyDesc.value : undefined;
174
+ let options = {
175
+ equals: propertyDesc?.equals,
176
+ description: propertyDesc?.description
177
+ };
178
+ let decorator = function (target, key, desc, _meta, isClassicDecorator) {
179
+ let fieldDesc = isClassicDecorator ? {
180
+ initializer: initializer || (() => value)
181
+ } : desc;
182
+ return descriptorForField([target, key, fieldDesc], options);
183
+ };
184
+ setClassicDecorator(decorator);
185
+ return decorator;
186
+ }
187
+ function descriptorForField([target, key, desc], options) {
188
+ let {
189
+ getter,
190
+ setter
191
+ } = trackedData(key, desc ? desc.initializer : undefined);
192
+ let equals = options?.equals;
193
+ function get() {
194
+ let value = getter(this);
195
+
196
+ // Add the tag of the returned value if it is an array, since arrays
197
+ // should always cause updates if they are consumed and then changed
198
+ if (Array.isArray(value) || isEmberArray(value)) {
199
+ consumeTag(tagFor(value, '[]'));
200
+ }
201
+ return value;
202
+ }
203
+ function set(newValue) {
204
+ if (equals !== undefined && equals(untrack(() => getter(this)), newValue)) {
205
+ return;
206
+ }
207
+ setter(this, newValue);
208
+ dirtyTagFor(this, SELF_TAG);
209
+ }
210
+ let newDesc = {
211
+ enumerable: true,
212
+ configurable: true,
213
+ isTracked: true,
214
+ get,
215
+ set
216
+ };
217
+ COMPUTED_SETTERS.add(set);
218
+ meta(target).writeDescriptors(key, new TrackedDescriptor(get, set));
219
+ return newDesc;
220
+ }
221
+ class TrackedDescriptor {
222
+ constructor(_get, _set) {
223
+ this._get = _get;
224
+ this._set = _set;
225
+ CHAIN_PASS_THROUGH.add(this);
226
+ }
227
+ get(obj) {
228
+ return this._get.call(obj);
229
+ }
230
+ set(obj, _key, value) {
231
+ this._set.call(obj, value);
232
+ }
233
+ }
234
+
235
+ export { TrackedDescriptor as T, tracked as t };
@@ -0,0 +1,115 @@
1
+ import { d as dirtyTagFor, t as tagFor } from './meta-BJtIZDir.js';
2
+ import { c as consumeTag, b as createUpdatableTag, D as DIRTY_TAG } from './cache-CofLhaS4.js';
3
+
4
+ function trackedData(key, initializer) {
5
+ let values = new WeakMap();
6
+ let hasInitializer = typeof initializer === 'function';
7
+ function getter(self) {
8
+ consumeTag(tagFor(self, key));
9
+ let value;
10
+
11
+ // If the field has never been initialized, we should initialize it
12
+ if (hasInitializer && !values.has(self)) {
13
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- @fixme
14
+ value = initializer.call(self);
15
+ values.set(self, value);
16
+ } else {
17
+ value = values.get(self);
18
+ }
19
+ return value;
20
+ }
21
+ function setter(self, value) {
22
+ dirtyTagFor(self, key);
23
+ values.set(self, value);
24
+ }
25
+ return {
26
+ getter,
27
+ setter
28
+ };
29
+ }
30
+
31
+ /**
32
+ * A mutable reactive value.
33
+ *
34
+ * Reading `value` consumes the underlying tag (entangling with any active
35
+ * tracking frame), and writing `value` dirties it.
36
+ */
37
+
38
+ /**
39
+ * A reactive value that can only be read.
40
+ */
41
+
42
+ class TrackedValue {
43
+ #isFrozen = false;
44
+ #value;
45
+ #options;
46
+ #tag;
47
+ constructor(value, options) {
48
+ this.#value = value;
49
+ this.#options = options;
50
+ this.#tag = createUpdatableTag();
51
+ }
52
+
53
+ /**
54
+ * The underlying value.
55
+ *
56
+ * Reading entangles with the current tracking frame, and writing notifies
57
+ * consumers (unless the configured `equals` deems the new value equal to
58
+ * the current one).
59
+ */
60
+ get value() {
61
+ consumeTag(this.#tag);
62
+ return this.#value;
63
+ }
64
+ set value(value) {
65
+ this.set(value);
66
+ }
67
+
68
+ /**
69
+ * Function short-hand for reading `value`.
70
+ */
71
+ get = () => {
72
+ return this.value;
73
+ };
74
+
75
+ /**
76
+ * Function short-hand for assigning `value`.
77
+ *
78
+ * Returns `true` if the value changed (and consumers were notified),
79
+ * `false` if the new value was equal to the current one.
80
+ */
81
+ set = value => {
82
+ if (this.#isFrozen) {
83
+ throw new Error(`Cannot update a frozen TrackedValue${this.#options.description ? ` (\`${this.#options.description}\`)` : ''}`);
84
+ }
85
+ if (this.#options.equals(this.#value, value)) {
86
+ return false;
87
+ }
88
+ this.#value = value;
89
+ DIRTY_TAG(this.#tag);
90
+ return true;
91
+ };
92
+
93
+ /**
94
+ * Update the value based on the current value, without consuming it.
95
+ */
96
+ update = updater => {
97
+ this.set(updater(this.#value));
98
+ };
99
+
100
+ /**
101
+ * Prevents further updates, making the TrackedValue behave as a
102
+ * ReadOnlyReactive.
103
+ */
104
+ freeze = () => {
105
+ this.#isFrozen = true;
106
+ };
107
+ }
108
+ function trackedValue(value, options) {
109
+ return new TrackedValue(value, {
110
+ equals: options?.equals ?? Object.is,
111
+ description: options?.description
112
+ });
113
+ }
114
+
115
+ export { TrackedValue as T, trackedData as a, trackedValue as t };
@@ -354,7 +354,7 @@ class Transition {
354
354
  @public
355
355
  */
356
356
  finally(callback, label) {
357
- // @ts-expect-error @types/rsvp doesn't have the correct signiture for RSVP.Promise.finally
357
+ // @ts-expect-error @types/rsvp doesn't have the correct signature for RSVP.Promise.finally
358
358
  return this.promise.finally(callback, label);
359
359
  }
360
360