ember-source 7.3.0-alpha.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 (102) hide show
  1. package/build-metadata.json +3 -3
  2. package/dist/dev/packages/@ember/-internals/glimmer/index.js +6 -6
  3. package/dist/dev/packages/@ember/-internals/metal/index.js +8 -8
  4. package/dist/dev/packages/@ember/-internals/runtime/lib/mixins/-proxy.js +2 -2
  5. package/dist/dev/packages/@ember/-internals/runtime/lib/mixins/target_action_support.js +1 -1
  6. package/dist/dev/packages/@ember/-internals/views/lib/system/event_dispatcher.js +1 -1
  7. package/dist/dev/packages/@ember/-internals/views/lib/views/core_view.js +1 -1
  8. package/dist/dev/packages/@ember/application/index.js +1 -1
  9. package/dist/dev/packages/@ember/application/instance.js +4 -4
  10. package/dist/dev/packages/@ember/array/index.js +3 -3
  11. package/dist/dev/packages/@ember/array/proxy.js +3 -3
  12. package/dist/dev/packages/@ember/component/index.js +2 -2
  13. package/dist/dev/packages/@ember/controller/index.js +2 -2
  14. package/dist/dev/packages/@ember/engine/index.js +2 -2
  15. package/dist/dev/packages/@ember/object/computed.js +2 -2
  16. package/dist/dev/packages/@ember/object/core.js +2 -2
  17. package/dist/dev/packages/@ember/object/index.js +4 -4
  18. package/dist/dev/packages/@ember/object/lib/computed/computed_macros.js +3 -3
  19. package/dist/dev/packages/@ember/object/lib/computed/reduce_computed_macros.js +1 -1
  20. package/dist/dev/packages/@ember/object/mixin.js +1 -1
  21. package/dist/dev/packages/@ember/object/observable.js +3 -3
  22. package/dist/dev/packages/@ember/object/promise-proxy-mixin.js +2 -2
  23. package/dist/dev/packages/@ember/renderer/index.js +1 -1
  24. package/dist/dev/packages/@ember/routing/route.js +3 -3
  25. package/dist/dev/packages/@ember/routing/router.js +2 -2
  26. package/dist/dev/packages/@ember/service/index.js +1 -1
  27. package/dist/dev/packages/@glimmer/node/index.js +2 -2
  28. package/dist/dev/packages/@glimmer/runtime/index.js +3 -3
  29. package/dist/dev/packages/@glimmer/tracking/index.js +1 -1
  30. package/dist/dev/packages/@glimmer/validator/index.js +1 -1
  31. package/dist/dev/packages/ember/version.js +1 -1
  32. package/dist/dev/packages/shared-chunks/{alias-DpqL1qx6.js → alias-CT_thCad.js} +2 -2
  33. package/dist/dev/packages/shared-chunks/{api-C0PAtEgQ.js → api-Dz70AUL_.js} +6 -4
  34. package/dist/dev/packages/shared-chunks/{array-CVEnNWng.js → array-DvaweI_T.js} +1 -1
  35. package/dist/dev/packages/shared-chunks/{computed-BPCtuOxQ.js → computed-DGxbeUbf.js} +1 -6
  36. package/dist/dev/packages/shared-chunks/{index-CCyXUNBa.js → index-D1AjYv31.js} +3 -3
  37. package/dist/dev/packages/shared-chunks/{injected_property-CbBLr5jt.js → injected_property-DbXd6Gax.js} +1 -1
  38. package/dist/dev/packages/shared-chunks/{property_set-qCUylPEK.js → property_set-CVlVgdor.js} +1 -1
  39. package/dist/dev/packages/shared-chunks/{rehydrate-builder-C6k1XhET.js → rehydrate-builder-CsnkZkur.js} +1 -1
  40. package/dist/dev/packages/shared-chunks/{render-87_sKZ_k.js → render-CtH73XOv.js} +10 -5
  41. package/dist/dev/packages/shared-chunks/{serialize-builder-BlxBjwO-.js → serialize-builder-D1oAeiyl.js} +1 -1
  42. package/dist/dev/packages/shared-chunks/{set_properties-C4TSebH6.js → set_properties-CEUT_EJn.js} +2 -2
  43. package/dist/dev/packages/shared-chunks/{setup-registry-BHdDJATP.js → setup-registry-DQ3c4Juo.js} +6 -6
  44. package/dist/dev/packages/shared-chunks/{textarea-C4lYkaHj.js → textarea-DEvw4ezm.js} +1 -1
  45. package/dist/dev/packages/shared-chunks/tracked-57EW14Ny.js +253 -0
  46. package/dist/dev/packages/shared-chunks/tracked-value-DhyJmrhG.js +115 -0
  47. package/dist/prod/packages/@ember/-internals/glimmer/index.js +6 -6
  48. package/dist/prod/packages/@ember/-internals/metal/index.js +8 -8
  49. package/dist/prod/packages/@ember/-internals/runtime/lib/mixins/-proxy.js +2 -2
  50. package/dist/prod/packages/@ember/-internals/runtime/lib/mixins/target_action_support.js +1 -1
  51. package/dist/prod/packages/@ember/-internals/views/lib/system/event_dispatcher.js +1 -1
  52. package/dist/prod/packages/@ember/-internals/views/lib/views/core_view.js +1 -1
  53. package/dist/prod/packages/@ember/application/index.js +1 -1
  54. package/dist/prod/packages/@ember/application/instance.js +3 -3
  55. package/dist/prod/packages/@ember/array/index.js +3 -3
  56. package/dist/prod/packages/@ember/array/proxy.js +3 -3
  57. package/dist/prod/packages/@ember/component/index.js +2 -2
  58. package/dist/prod/packages/@ember/controller/index.js +2 -2
  59. package/dist/prod/packages/@ember/engine/index.js +2 -2
  60. package/dist/prod/packages/@ember/object/computed.js +2 -2
  61. package/dist/prod/packages/@ember/object/index.js +4 -4
  62. package/dist/prod/packages/@ember/object/lib/computed/computed_macros.js +3 -3
  63. package/dist/prod/packages/@ember/object/lib/computed/reduce_computed_macros.js +1 -1
  64. package/dist/prod/packages/@ember/object/mixin.js +1 -1
  65. package/dist/prod/packages/@ember/object/observable.js +3 -3
  66. package/dist/prod/packages/@ember/object/promise-proxy-mixin.js +2 -2
  67. package/dist/prod/packages/@ember/renderer/index.js +1 -1
  68. package/dist/prod/packages/@ember/routing/route.js +3 -3
  69. package/dist/prod/packages/@ember/routing/router.js +2 -2
  70. package/dist/prod/packages/@ember/service/index.js +1 -1
  71. package/dist/prod/packages/@glimmer/node/index.js +2 -2
  72. package/dist/prod/packages/@glimmer/runtime/index.js +3 -3
  73. package/dist/prod/packages/@glimmer/tracking/index.js +1 -1
  74. package/dist/prod/packages/@glimmer/validator/index.js +1 -1
  75. package/dist/prod/packages/ember/version.js +1 -1
  76. package/dist/prod/packages/shared-chunks/{alias-Bod6qdNp.js → alias-CHHuE0LE.js} +2 -2
  77. package/dist/prod/packages/shared-chunks/{api-CQexacBn.js → api-DzOa0Acr.js} +6 -4
  78. package/dist/prod/packages/shared-chunks/{array-BzReKMeW.js → array-CnXdmzOG.js} +1 -1
  79. package/dist/prod/packages/shared-chunks/{computed-DtIStxvq.js → computed-BNdMwGhH.js} +1 -6
  80. package/dist/prod/packages/shared-chunks/{index-npr2B-vu.js → index-CvQQ6l11.js} +3 -3
  81. package/dist/prod/packages/shared-chunks/{injected_property-Y-FadDej.js → injected_property-DqQ0XV7k.js} +1 -1
  82. package/dist/prod/packages/shared-chunks/{property_set-BaQJdVfS.js → property_set-CkLe4ht8.js} +1 -1
  83. package/dist/prod/packages/shared-chunks/{rehydrate-builder-Blt1x9MP.js → rehydrate-builder-n_8RCUj9.js} +1 -1
  84. package/dist/prod/packages/shared-chunks/{render-Dx7lr1hR.js → render-Bf7GviCY.js} +10 -5
  85. package/dist/prod/packages/shared-chunks/{serialize-builder-BvAXYHTr.js → serialize-builder-CsG9WHVw.js} +1 -1
  86. package/dist/prod/packages/shared-chunks/{set_properties-Qxhw4qzw.js → set_properties-Cs3rVemD.js} +2 -2
  87. package/dist/prod/packages/shared-chunks/{setup-registry-Dfu8EyLU.js → setup-registry-kOGgOucf.js} +6 -6
  88. package/dist/prod/packages/shared-chunks/{textarea-DOmZ1x0E.js → textarea-DMmdvgk2.js} +1 -1
  89. package/dist/prod/packages/shared-chunks/tracked-DvOpYI0o.js +235 -0
  90. package/dist/prod/packages/shared-chunks/tracked-value-CR6kx-73.js +115 -0
  91. package/docs/data.json +149 -10
  92. package/package.json +1 -1
  93. package/types/stable/@ember/-internals/glimmer/lib/glimmer-tracking-docs.d.ts +68 -0
  94. package/types/stable/@ember/-internals/metal/lib/tracked.d.ts +53 -6
  95. package/types/stable/@glimmer/tracking/index.d.ts +70 -1
  96. package/types/stable/@glimmer/validator/index.d.ts +1 -0
  97. package/types/stable/@glimmer/validator/lib/tracked-value.d.ts +58 -0
  98. package/types/stable/index.d.ts +1 -0
  99. package/dist/dev/packages/shared-chunks/tracked-DEyf0T_X.js +0 -148
  100. package/dist/dev/packages/shared-chunks/tracked-data-DgqqRdYO.js +0 -31
  101. package/dist/prod/packages/shared-chunks/tracked-B9380JtC.js +0 -132
  102. package/dist/prod/packages/shared-chunks/tracked-data-CHq42QHb.js +0 -31
@@ -1,6 +1,7 @@
1
1
  declare module '@glimmer/tracking' {
2
2
  export { tracked } from "@ember/-internals/metal/lib/tracked";
3
3
  export { cached } from "@ember/-internals/metal/lib/cached";
4
+ export type { Reactive, ReadOnlyReactive, TrackedValue, } from "@glimmer/validator/lib/tracked-value";
4
5
  /**
5
6
  In order to tell Ember a value might change, we need to mark it as trackable.
6
7
  Trackable values are values that:
@@ -36,7 +37,7 @@ declare module '@glimmer/tracking' {
36
37
  plusOne() {
37
38
  this.count += 1;
38
39
  }
39
-
40
+
40
41
  <template>
41
42
  <div>Count: {{this.count}}</div>
42
43
  <div>Times Ten: {{this.timesTen}}</div>
@@ -141,6 +142,74 @@ declare module '@glimmer/tracking' {
141
142
  });
142
143
  ```
143
144
 
145
+ Calling `tracked` with an initial value creates a standalone reactive
146
+ value, usable outside of classes:
147
+
148
+ ```js
149
+ import { tracked } from '@glimmer/tracking';
150
+
151
+ const count = tracked(0);
152
+
153
+ count.value; // read the value, entangling with any tracking context
154
+ count.value = 1; // write the value, notifying consumers
155
+ count.get(); // function shorthand for reading
156
+ count.set(2); // function shorthand for writing
157
+ count.update((n) => n + 1); // write based on the current value, without entangling
158
+ count.freeze(); // prevent all future writes
159
+ ```
160
+
161
+ Reading `value` in a template (or in a getter used by a template) will
162
+ rerender just like a `@tracked` property:
163
+
164
+ ```gjs
165
+ import { tracked } from '@glimmer/tracking';
166
+ import { on } from '@ember/modifier';
167
+
168
+ const count = tracked(0);
169
+ const increment = () => count.value++;
170
+
171
+ <template>
172
+ Count is: {{count.value}}
173
+
174
+ <button {{on "click" increment}}>add one</button>
175
+ </template>
176
+ ```
177
+
178
+ This form accepts an options object containing an `equals` function, which
179
+ decides whether a written value should notify consumers (it defaults to
180
+ `Object.is`), and a `description` used for debugging:
181
+
182
+ ```js
183
+ const count = tracked(0, { equals: (a, b) => a === b });
184
+
185
+ count.value = 0; // does not notify consumers, the value did not change
186
+ ```
187
+
188
+ Note: when `tracked` is called with a single plain object whose keys are all
189
+ drawn from `value`, `initializer`, `equals`, and `description`, it is treated
190
+ as the configuration object for a decorator (or classic-class field), not as a
191
+ standalone value wrapping that object. To create a standalone reactive value
192
+ around such an object, pass it as an initial value and include a (possibly
193
+ empty) options argument: `tracked({ value: 5 }, {})`.
194
+
195
+ The `@tracked` decorator accepts the same options. By default, setting a
196
+ `@tracked` property always notifies consumers, even when setting the
197
+ property to the same value; passing `equals` opts in to equality-based
198
+ notification instead:
199
+
200
+ ```js
201
+ import { tracked } from '@glimmer/tracking';
202
+
203
+ class Counter {
204
+ @tracked({ equals: (a, b) => a === b }) count = 0;
205
+
206
+ noop = () => {
207
+ // does not notify consumers, the value did not change
208
+ this.count = this.count;
209
+ };
210
+ }
211
+ ```
212
+
144
213
  @method tracked
145
214
  @static
146
215
  @for @glimmer/tracking
@@ -8,6 +8,7 @@ declare module '@glimmer/validator' {
8
8
  export { debug } from "@glimmer/validator/lib/debug";
9
9
  export { dirtyTagFor, tagFor, type TagMeta, tagMetaFor } from "@glimmer/validator/lib/meta";
10
10
  export { trackedData } from "@glimmer/validator/lib/tracked-data";
11
+ export { type Reactive, type ReadOnlyReactive, TrackedValue, trackedValue, } from "@glimmer/validator/lib/tracked-value";
11
12
  export { beginTrackFrame, beginUntrackFrame, type Cache, consumeTag, createCache, endTrackFrame, endUntrackFrame, getValue, isConst, isTracking, resetTracking, track, untrack, } from "@glimmer/validator/lib/tracking";
12
13
  export { ALLOW_CYCLES, bump, combine, COMPUTE, CONSTANT, CONSTANT_TAG, createTag, createUpdatableTag, CURRENT_TAG, CurrentTag, DIRTY_TAG as dirtyTag, INITIAL, isConstTag, type Revision, UPDATE_TAG as updateTag, validateTag, valueForTag, VOLATILE, VOLATILE_TAG, VolatileTag, } from "@glimmer/validator/lib/validators";
13
14
  export type { CombinatorTag, ConstantTag, DirtyableTag, Tag, UpdatableTag, } from "@glimmer/interfaces";
@@ -0,0 +1,58 @@
1
+ declare module '@glimmer/validator/lib/tracked-value' {
2
+ import type { ReactiveOptions } from "@glimmer/validator/lib/collections/types";
3
+ /**
4
+ * A mutable reactive value.
5
+ *
6
+ * Reading `value` consumes the underlying tag (entangling with any active
7
+ * tracking frame), and writing `value` dirties it.
8
+ */
9
+ export interface Reactive<Value> {
10
+ value: Value;
11
+ }
12
+ /**
13
+ * A reactive value that can only be read.
14
+ */
15
+ export interface ReadOnlyReactive<Value> extends Reactive<Value> {
16
+ readonly value: Value;
17
+ }
18
+ export class TrackedValue<Value = unknown> implements Reactive<Value> {
19
+ #private;
20
+ constructor(value: Value, options: ReactiveOptions<Value>);
21
+ /**
22
+ * The underlying value.
23
+ *
24
+ * Reading entangles with the current tracking frame, and writing notifies
25
+ * consumers (unless the configured `equals` deems the new value equal to
26
+ * the current one).
27
+ */
28
+ get value(): Value;
29
+ set value(value: Value);
30
+ /**
31
+ * Function short-hand for reading `value`.
32
+ */
33
+ get: () => Value;
34
+ /**
35
+ * Function short-hand for assigning `value`.
36
+ *
37
+ * Returns `true` if the value changed (and consumers were notified),
38
+ * `false` if the new value was equal to the current one.
39
+ */
40
+ set: (value: Value) => boolean;
41
+ /**
42
+ * Update the value based on the current value, without consuming it.
43
+ */
44
+ update: (updater: (value: Value) => Value) => void;
45
+ /**
46
+ * Prevents further updates, making the TrackedValue behave as a
47
+ * ReadOnlyReactive.
48
+ */
49
+ freeze: () => void;
50
+ }
51
+ export function trackedValue<Value>(
52
+ value: Value,
53
+ options?: {
54
+ equals?: (a: Value, b: Value) => boolean;
55
+ description?: string;
56
+ }
57
+ ): TrackedValue<Value>;
58
+ }
@@ -97,6 +97,7 @@
97
97
  /// <reference path="./@glimmer/validator/lib/validators.d.ts" />
98
98
  /// <reference path="./@glimmer/validator/lib/utils.d.ts" />
99
99
  /// <reference path="./@glimmer/validator/lib/tracking.d.ts" />
100
+ /// <reference path="./@glimmer/validator/lib/tracked-value.d.ts" />
100
101
  /// <reference path="./@glimmer/validator/lib/tracked-data.d.ts" />
101
102
  /// <reference path="./@glimmer/validator/lib/meta.d.ts" />
102
103
  /// <reference path="./@glimmer/validator/lib/debug.d.ts" />
@@ -1,148 +0,0 @@
1
- import { meta } from '../@ember/-internals/meta/lib/meta.js';
2
- import { isEmberArray } from '../@ember/array/-internals.js';
3
- import '../@ember/debug/index.js';
4
- import { c as consumeTag } from './cache-DGDPVCpC.js';
5
- import { d as dirtyTagFor, t as tagFor } from './meta-BqC7f9Ia.js';
6
- import { t as trackedData } from './tracked-data-DgqqRdYO.js';
7
- import { S as SELF_TAG, C as CHAIN_PASS_THROUGH } from './chain-tags-uWSImHzB.js';
8
- import { s as setClassicDecorator, i as isElementDescriptor, C as COMPUTED_SETTERS } from './decorator-B5Uh5NFI.js';
9
- import { assert } from '../@ember/debug/lib/assert.js';
10
-
11
- /**
12
- @decorator
13
- @private
14
-
15
- Marks a property as tracked.
16
-
17
- By default, a component's properties are expected to be static,
18
- meaning you are not able to update them and have the template update accordingly.
19
- Marking a property as tracked means that when that property changes,
20
- a rerender of the component is scheduled so the template is kept up to date.
21
-
22
- There are two usages for the `@tracked` decorator, shown below.
23
-
24
- @example No dependencies
25
-
26
- If you don't pass an argument to `@tracked`, only changes to that property
27
- will be tracked:
28
-
29
- ```typescript
30
- import Component from '@glimmer/component';
31
- import { tracked } from '@glimmer/tracking';
32
-
33
- export default class MyComponent extends Component {
34
- @tracked
35
- remainingApples = 10
36
- }
37
- ```
38
-
39
- When something changes the component's `remainingApples` property, the rerender
40
- will be scheduled.
41
-
42
- @example Dependents
43
-
44
- In the case that you have a computed property that depends other
45
- properties, you want to track both so that when one of the
46
- dependents change, a rerender is scheduled.
47
-
48
- In the following example we have two properties,
49
- `eatenApples`, and `remainingApples`.
50
-
51
- ```typescript
52
- import Component from '@glimmer/component';
53
- import { tracked } from '@glimmer/tracking';
54
-
55
- const totalApples = 100;
56
-
57
- export default class MyComponent extends Component {
58
- @tracked
59
- eatenApples = 0
60
-
61
- get remainingApples() {
62
- return totalApples - this.eatenApples;
63
- }
64
-
65
- increment() {
66
- this.eatenApples = this.eatenApples + 1;
67
- }
68
- }
69
- ```
70
-
71
- @param dependencies Optional dependents to be tracked.
72
- */
73
-
74
- function tracked(...args) {
75
- (!(!(isElementDescriptor(args.slice(0, 3)) && args.length === 5 && args[4] === true)) && assert(`@tracked can only be used directly as a native decorator. If you're using tracked in classic classes, add parenthesis to call it like a function: tracked()`, !(isElementDescriptor(args.slice(0, 3)) && args.length === 5 && args[4] === true)));
76
- if (!isElementDescriptor(args)) {
77
- let propertyDesc = args[0];
78
- (!(args.length === 0 || typeof propertyDesc === 'object' && propertyDesc !== null) && assert(`tracked() may only receive an options object containing 'value' or 'initializer', received ${propertyDesc}`, args.length === 0 || typeof propertyDesc === 'object' && propertyDesc !== null));
79
- if (propertyDesc) {
80
- let keys = Object.keys(propertyDesc);
81
- (!(keys.length <= 1 && (keys[0] === undefined || keys[0] === 'value' || keys[0] === 'initializer')) && assert(`The options object passed to tracked() may only contain a 'value' or 'initializer' property, not both. Received: [${keys}]`, keys.length <= 1 && (keys[0] === undefined || keys[0] === 'value' || keys[0] === 'initializer')));
82
- (!(!('initializer' in propertyDesc) || typeof propertyDesc.initializer === 'function') && assert(`The initializer passed to tracked must be a function. Received ${propertyDesc.initializer}`, !('initializer' in propertyDesc) || typeof propertyDesc.initializer === 'function'));
83
- }
84
- let initializer = propertyDesc ? propertyDesc.initializer : undefined;
85
- let value = propertyDesc ? propertyDesc.value : undefined;
86
- let decorator = function (target, key, _desc, _meta, isClassicDecorator) {
87
- (!(isClassicDecorator) && assert(`You attempted to set a default value for ${key} with the @tracked({ value: 'default' }) syntax. You can only use this syntax with classic classes. For native classes, you can use class initializers: @tracked field = 'default';`, isClassicDecorator));
88
- let fieldDesc = {
89
- initializer: initializer || (() => value)
90
- };
91
- return descriptorForField([target, key, fieldDesc]);
92
- };
93
- setClassicDecorator(decorator);
94
- return decorator;
95
- }
96
- return descriptorForField(args);
97
- }
98
- {
99
- // Normally this isn't a classic decorator, but we want to throw a helpful
100
- // error in development so we need it to treat it like one
101
- setClassicDecorator(tracked);
102
- }
103
- function descriptorForField([target, key, desc]) {
104
- (!(!desc || !desc.value && !desc.get && !desc.set) && assert(`You attempted to use @tracked on ${key}, but that element is not a class field. @tracked is only usable on class fields. Native getters and setters will autotrack add any tracked fields they encounter, so there is no need mark getters and setters with @tracked.`, !desc || !desc.value && !desc.get && !desc.set));
105
- let {
106
- getter,
107
- setter
108
- } = trackedData(key, desc ? desc.initializer : undefined);
109
- function get() {
110
- let value = getter(this);
111
-
112
- // Add the tag of the returned value if it is an array, since arrays
113
- // should always cause updates if they are consumed and then changed
114
- if (Array.isArray(value) || isEmberArray(value)) {
115
- consumeTag(tagFor(value, '[]'));
116
- }
117
- return value;
118
- }
119
- function set(newValue) {
120
- setter(this, newValue);
121
- dirtyTagFor(this, SELF_TAG);
122
- }
123
- let newDesc = {
124
- enumerable: true,
125
- configurable: true,
126
- isTracked: true,
127
- get,
128
- set
129
- };
130
- COMPUTED_SETTERS.add(set);
131
- meta(target).writeDescriptors(key, new TrackedDescriptor(get, set));
132
- return newDesc;
133
- }
134
- class TrackedDescriptor {
135
- constructor(_get, _set) {
136
- this._get = _get;
137
- this._set = _set;
138
- CHAIN_PASS_THROUGH.add(this);
139
- }
140
- get(obj) {
141
- return this._get.call(obj);
142
- }
143
- set(obj, _key, value) {
144
- this._set.call(obj, value);
145
- }
146
- }
147
-
148
- export { TrackedDescriptor as T, tracked as t };
@@ -1,31 +0,0 @@
1
- import { d as dirtyTagFor, t as tagFor } from './meta-BqC7f9Ia.js';
2
- import { c as consumeTag } from './cache-DGDPVCpC.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
- export { trackedData as t };
@@ -1,132 +0,0 @@
1
- import { meta } from '../@ember/-internals/meta/lib/meta.js';
2
- import { isEmberArray } from '../@ember/array/-internals.js';
3
- import { c as consumeTag } from './cache-CofLhaS4.js';
4
- import { d as dirtyTagFor, t as tagFor } from './meta-BJtIZDir.js';
5
- import { t as trackedData } from './tracked-data-CHq42QHb.js';
6
- import { C as CHAIN_PASS_THROUGH, S as SELF_TAG } from './chain-tags-B2J7DsxO.js';
7
- import { i as isElementDescriptor, s as setClassicDecorator, C as COMPUTED_SETTERS } 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
- function tracked(...args) {
73
- if (!isElementDescriptor(args)) {
74
- let propertyDesc = args[0];
75
- let initializer = propertyDesc ? propertyDesc.initializer : undefined;
76
- let value = propertyDesc ? propertyDesc.value : undefined;
77
- let decorator = function (target, key, _desc, _meta, isClassicDecorator) {
78
- let fieldDesc = {
79
- initializer: initializer || (() => value)
80
- };
81
- return descriptorForField([target, key, fieldDesc]);
82
- };
83
- setClassicDecorator(decorator);
84
- return decorator;
85
- }
86
- return descriptorForField(args);
87
- }
88
- function descriptorForField([target, key, desc]) {
89
- let {
90
- getter,
91
- setter
92
- } = trackedData(key, desc ? desc.initializer : undefined);
93
- function get() {
94
- let value = getter(this);
95
-
96
- // Add the tag of the returned value if it is an array, since arrays
97
- // should always cause updates if they are consumed and then changed
98
- if (Array.isArray(value) || isEmberArray(value)) {
99
- consumeTag(tagFor(value, '[]'));
100
- }
101
- return value;
102
- }
103
- function set(newValue) {
104
- setter(this, newValue);
105
- dirtyTagFor(this, SELF_TAG);
106
- }
107
- let newDesc = {
108
- enumerable: true,
109
- configurable: true,
110
- isTracked: true,
111
- get,
112
- set
113
- };
114
- COMPUTED_SETTERS.add(set);
115
- meta(target).writeDescriptors(key, new TrackedDescriptor(get, set));
116
- return newDesc;
117
- }
118
- class TrackedDescriptor {
119
- constructor(_get, _set) {
120
- this._get = _get;
121
- this._set = _set;
122
- CHAIN_PASS_THROUGH.add(this);
123
- }
124
- get(obj) {
125
- return this._get.call(obj);
126
- }
127
- set(obj, _key, value) {
128
- this._set.call(obj, value);
129
- }
130
- }
131
-
132
- export { TrackedDescriptor as T, tracked as t };
@@ -1,31 +0,0 @@
1
- import { d as dirtyTagFor, t as tagFor } from './meta-BJtIZDir.js';
2
- import { c as consumeTag } 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
- export { trackedData as t };