Skip to content

Commit 4fc94e7

Browse files
committed
WIP: Kill Array mixins, some computed macros
1 parent f74a525 commit 4fc94e7

File tree

104 files changed

+355
-9713
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+355
-9713
lines changed

broccoli/amd-compat-entrypoints/ember.debug.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,18 +137,12 @@ d('@ember/application/lib/lazy_load', emberApplicationLibLazyLoad);
137137
import * as emberApplicationNamespace from '@ember/application/namespace';
138138
d('@ember/application/namespace', emberApplicationNamespace);
139139

140-
import * as emberArrayinternals from '@ember/array/-internals';
141-
d('@ember/array/-internals', emberArrayinternals);
142-
143140
import * as emberArrayIndex from '@ember/array/index';
144141
d('@ember/array/index', emberArrayIndex);
145142

146143
import * as emberArrayLibMakeArray from '@ember/array/lib/make-array';
147144
d('@ember/array/lib/make-array', emberArrayLibMakeArray);
148145

149-
import * as emberArrayMutable from '@ember/array/mutable';
150-
d('@ember/array/mutable', emberArrayMutable);
151-
152146
import * as emberCanaryFeaturesIndex from '@ember/canary-features/index';
153147
d('@ember/canary-features/index', emberCanaryFeaturesIndex);
154148

@@ -245,9 +239,6 @@ d('@ember/object/internals', emberObjectInternals);
245239
import * as emberObjectLibComputedComputedMacros from '@ember/object/lib/computed/computed_macros';
246240
d('@ember/object/lib/computed/computed_macros', emberObjectLibComputedComputedMacros);
247241

248-
import * as emberObjectLibComputedReduceComputedMacros from '@ember/object/lib/computed/reduce_computed_macros';
249-
d('@ember/object/lib/computed/reduce_computed_macros', emberObjectLibComputedReduceComputedMacros);
250-
251242
import * as emberObjectMixin from '@ember/object/mixin';
252243
d('@ember/object/mixin', emberObjectMixin);
253244

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,14 @@
9999
"ember-cli-typescript-blueprint-polyfill": "^0.1.0",
100100
"ember-cli-version-checker": "^5.1.2",
101101
"ember-router-generator": "^2.0.0",
102+
"ember-tracked-storage-polyfill": "^1.0.0",
102103
"inflection": "^2.0.1",
103104
"route-recognizer": "^0.3.4",
104105
"router_js": "^8.0.5",
105106
"semver": "^7.5.2",
106107
"silent-error": "^1.1.1",
107-
"simple-html-tokenizer": "^0.5.11"
108+
"simple-html-tokenizer": "^0.5.11",
109+
"tracked-built-ins": "^4.0.0"
108110
},
109111
"devDependencies": {
110112
"@aws-sdk/client-s3": "^3.731.0",
@@ -224,11 +226,9 @@
224226
"@ember/application/instance.js": "ember-source/@ember/application/instance.js",
225227
"@ember/application/lib/lazy_load.js": "ember-source/@ember/application/lib/lazy_load.js",
226228
"@ember/application/namespace.js": "ember-source/@ember/application/namespace.js",
227-
"@ember/array/-internals.js": "ember-source/@ember/array/-internals.js",
228229
"@ember/array/index.js": "ember-source/@ember/array/index.js",
229230
"@ember/array/lib/make-array.js": "ember-source/@ember/array/lib/make-array.js",
230231
"@ember/array/make.js": "ember-source/@ember/array/make.js",
231-
"@ember/array/mutable.js": "ember-source/@ember/array/mutable.js",
232232
"@ember/canary-features/index.js": "ember-source/@ember/canary-features/index.js",
233233
"@ember/component/helper.js": "ember-source/@ember/component/helper.js",
234234
"@ember/component/index.js": "ember-source/@ember/component/index.js",
@@ -376,7 +376,8 @@
376376
"ember/version.js": "ember-source/ember/version.js",
377377
"route-recognizer/index.js": "ember-source/route-recognizer/index.js",
378378
"router_js/index.js": "ember-source/router_js/index.js",
379-
"rsvp/index.js": "ember-source/rsvp/index.js"
379+
"rsvp/index.js": "ember-source/rsvp/index.js",
380+
"tracked-built-ins/index.js": "ember-source/tracked-built-ins/index.js"
380381
}
381382
},
382383
"typesVersions": {

packages/@ember/-internals/glimmer/lib/utils/iterator.ts

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
import { objectAt } from '@ember/-internals/metal';
2-
import type EmberArray from '@ember/array';
3-
import { isEmberArray } from '@ember/array/-internals';
41
import { isObject } from '@ember/-internals/utils';
52
import type { Nullable } from '@ember/-internals/utility-types';
63
import type { IteratorDelegate } from '@glimmer/reference';
74
import { consumeTag, isTracking, tagFor } from '@glimmer/validator';
85
import { EachInWrapper } from '../helpers/each-in';
9-
import type { NativeArray } from '@ember/array';
106

117
export default function toIterator(iterable: unknown): Nullable<IteratorDelegate> {
128
if (iterable instanceof EachInWrapper) {
@@ -21,7 +17,7 @@ function toEachInIterator(iterable: unknown) {
2117
return null;
2218
}
2319

24-
if (Array.isArray(iterable) || isEmberArray(iterable)) {
20+
if (Array.isArray(iterable)) {
2521
return ObjectIterator.fromIndexable(iterable);
2622
} else if (isNativeIterable(iterable)) {
2723
return MapLikeNativeIterator.from(iterable as Iterable<[unknown, unknown]>);
@@ -39,8 +35,6 @@ function toEachIterator(iterable: unknown) {
3935

4036
if (Array.isArray(iterable)) {
4137
return ArrayIterator.from(iterable);
42-
} else if (isEmberArray(iterable)) {
43-
return EmberArrayIterator.from(iterable);
4438
} else if (isNativeIterable(iterable)) {
4539
return ArrayLikeNativeIterator.from(iterable);
4640
} else if (hasForEach(iterable)) {
@@ -101,20 +95,6 @@ class ArrayIterator extends BoundedIterator {
10195
}
10296
}
10397

104-
class EmberArrayIterator extends BoundedIterator {
105-
static from(iterable: EmberArray<unknown> | NativeArray<unknown>) {
106-
return iterable.length > 0 ? new this(iterable) : null;
107-
}
108-
109-
constructor(private array: EmberArray<unknown> | NativeArray<unknown>) {
110-
super(array.length);
111-
}
112-
113-
valueFor(position: number): unknown {
114-
return objectAt(this.array as any, position);
115-
}
116-
}
117-
11898
class ObjectIterator extends BoundedIterator {
11999
static fromIndexable(obj: Indexable) {
120100
let keys = Object.keys(obj);

packages/@ember/-internals/glimmer/tests/integration/components/contextual-components-test.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import { moduleFor, RenderingTestCase, applyMixins, strip, runTask } from 'inter
33

44
import { isEmpty } from '@ember/utils';
55
import { action } from '@ember/object';
6-
import { A as emberA } from '@ember/array';
76

87
import { Component } from '../../utils/helpers';
98

9+
import { tracked } from 'tracked-built-ins';
10+
1011
moduleFor(
1112
'Components test: contextual components',
1213
class extends RenderingTestCase {
@@ -1160,7 +1161,7 @@ moduleFor(
11601161
});
11611162

11621163
this.render('{{component (component "my-link") params=this.allParams}}', {
1163-
allParams: emberA(['a', 'b']),
1164+
allParams: tracked(['a', 'b']),
11641165
});
11651166

11661167
this.assertText('ab');
@@ -1169,23 +1170,23 @@ moduleFor(
11691170

11701171
this.assertText('ab');
11711172

1172-
runTask(() => this.context.get('allParams').pushObject('c'));
1173+
runTask(() => this.context.get('allParams').push('c'));
11731174

11741175
this.assertText('abc');
11751176

1176-
runTask(() => this.context.get('allParams').popObject());
1177+
runTask(() => this.context.get('allParams').pop());
11771178

11781179
this.assertText('ab');
11791180

1180-
runTask(() => this.context.get('allParams').clear());
1181+
runTask(() => this.context.get('allParams').splice(0, 2));
11811182

11821183
this.assertText('');
11831184

1184-
runTask(() => this.context.set('allParams', emberA(['1', '2'])));
1185+
runTask(() => this.context.set('allParams', ['1', '2']));
11851186

11861187
this.assertText('12');
11871188

1188-
runTask(() => this.context.set('allParams', emberA(['a', 'b'])));
1189+
runTask(() => this.context.set('allParams', ['a', 'b']));
11891190

11901191
this.assertText('ab');
11911192
}
@@ -1201,7 +1202,7 @@ moduleFor(
12011202
this.render(
12021203
'{{#let (hash link=(component "my-link")) as |c|}}{{c.link params=this.allParams}}{{/let}}',
12031204
{
1204-
allParams: emberA(['a', 'b']),
1205+
allParams: tracked(['a', 'b']),
12051206
}
12061207
);
12071208

@@ -1211,23 +1212,23 @@ moduleFor(
12111212

12121213
this.assertText('ab');
12131214

1214-
runTask(() => this.context.get('allParams').pushObject('c'));
1215+
runTask(() => this.context.get('allParams').push('c'));
12151216

12161217
this.assertText('abc');
12171218

1218-
runTask(() => this.context.get('allParams').popObject());
1219+
runTask(() => this.context.get('allParams').pop());
12191220

12201221
this.assertText('ab');
12211222

1222-
runTask(() => this.context.get('allParams').clear());
1223+
runTask(() => this.context.get('allParams').splice(0, 3));
12231224

12241225
this.assertText('');
12251226

1226-
runTask(() => this.context.set('allParams', emberA(['1', '2'])));
1227+
runTask(() => this.context.set('allParams', ['1', '2']));
12271228

12281229
this.assertText('12');
12291230

1230-
runTask(() => this.context.set('allParams', emberA(['a', 'b'])));
1231+
runTask(() => this.context.set('allParams', ['a', 'b']));
12311232

12321233
this.assertText('ab');
12331234
}

packages/@ember/-internals/glimmer/tests/integration/components/curly-components-test.js

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ import {
99
runLoopSettled,
1010
} from 'internal-test-helpers';
1111

12+
import { tracked as trackedBuiltIn } from 'tracked-built-ins';
13+
1214
import { action } from '@ember/object';
1315
import { run } from '@ember/runloop';
1416
import { DEBUG } from '@glimmer/env';
1517
import { tracked } from '@ember/-internals/metal';
1618
import { alias } from '@ember/object/computed';
1719
import Service, { service } from '@ember/service';
1820
import EmberObject, { set, get, computed, observer } from '@ember/object';
19-
import { A as emberA } from '@ember/array';
2021

2122
import { Component, compile, htmlSafe } from '../../utils/helpers';
2223
import { backtrackingMessageFor } from '../../utils/debug-stack';
@@ -1704,7 +1705,7 @@ moduleFor(
17041705
});
17051706

17061707
this.render('{{sample-component names=this.things}}', {
1707-
things: emberA(['Foo', 4, 'Bar']),
1708+
things: trackedBuiltIn(['Foo', 4, 'Bar']),
17081709
});
17091710

17101711
this.assertText('Foo4Bar');
@@ -1713,19 +1714,19 @@ moduleFor(
17131714

17141715
this.assertText('Foo4Bar');
17151716

1716-
runTask(() => this.context.get('things').pushObject(5));
1717+
runTask(() => this.context.get('things').push(5));
17171718

17181719
this.assertText('Foo4Bar5');
17191720

1720-
runTask(() => this.context.get('things').shiftObject());
1721+
runTask(() => this.context.get('things').shift());
17211722

17221723
this.assertText('4Bar5');
17231724

1724-
runTask(() => this.context.get('things').clear());
1725+
runTask(() => this.context.get('things').splice(0, 3));
17251726

17261727
this.assertText('');
17271728

1728-
runTask(() => this.context.set('things', emberA(['Foo', 4, 'Bar'])));
1729+
runTask(() => this.context.set('things', ['Foo', 4, 'Bar']));
17291730

17301731
this.assertText('Foo4Bar');
17311732
}
@@ -2563,7 +2564,7 @@ moduleFor(
25632564
template: 'Child: {{this.item}}.',
25642565
});
25652566

2566-
let items = emberA(['Tom', 'Dick', 'Harry']);
2567+
let items = trackedBuiltIn(['Tom', 'Dick', 'Harry']);
25672568

25682569
this.render('{{non-block items=this.items}}', { items });
25692570

@@ -2573,15 +2574,15 @@ moduleFor(
25732574

25742575
this.assertText('In layout. [Child: Tom.][Child: Dick.][Child: Harry.]');
25752576

2576-
runTask(() => this.context.get('items').pushObject('Sergio'));
2577+
runTask(() => this.context.get('items').push('Sergio'));
25772578

25782579
this.assertText('In layout. [Child: Tom.][Child: Dick.][Child: Harry.][Child: Sergio.]');
25792580

2580-
runTask(() => this.context.get('items').shiftObject());
2581+
runTask(() => this.context.get('items').shift());
25812582

25822583
this.assertText('In layout. [Child: Dick.][Child: Harry.][Child: Sergio.]');
25832584

2584-
runTask(() => this.context.set('items', emberA(['Tom', 'Dick', 'Harry'])));
2585+
runTask(() => this.context.set('items', ['Tom', 'Dick', 'Harry']));
25852586

25862587
this.assertText('In layout. [Child: Tom.][Child: Dick.][Child: Harry.]');
25872588
}
@@ -3006,7 +3007,7 @@ moduleFor(
30063007

30073008
init() {
30083009
super.init(...arguments);
3009-
this.options = emberA([]);
3010+
this.options = [];
30103011
this.value = null;
30113012
}
30123013

@@ -3017,11 +3018,16 @@ moduleFor(
30173018
}
30183019

30193020
registerOption(option) {
3020-
this.get('options').addObject(option);
3021+
if (this.get('options').indexOf(option) === -1) {
3022+
this.get('options').push(option);
3023+
}
30213024
}
30223025

30233026
unregisterOption(option) {
3024-
this.get('options').removeObject(option);
3027+
let index = this.get('options').indexOf(option);
3028+
if (index > -1) {
3029+
this.get('options').splice(index, 1);
3030+
}
30253031

30263032
this.updateValue();
30273033
}

packages/@ember/-internals/glimmer/tests/integration/components/life-cycle-test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { classes, moduleFor, RenderingTestCase, runTask, strip } from 'internal-
22

33
import { schedule } from '@ember/runloop';
44
import { set, setProperties } from '@ember/object';
5-
import { A as emberA } from '@ember/array';
65
import { getViewElement, getViewId } from '@ember/-internals/views';
76

87
import { Component } from '../../utils/helpers';
8+
import { tracked } from 'tracked-built-ins';
99

1010
class LifeCycleHooksTest extends RenderingTestCase {
1111
constructor() {
@@ -1433,7 +1433,7 @@ moduleFor(
14331433
template: NestedTemplate,
14341434
});
14351435

1436-
let array = emberA([{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }, { id: 5 }]);
1436+
let array = tracked([{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }, { id: 5 }]);
14371437

14381438
this.render(
14391439
strip`
@@ -1456,8 +1456,8 @@ moduleFor(
14561456
this.assertText('1AB2AB3AB4AB5AB6AB7AB');
14571457

14581458
runTask(() => {
1459-
array.removeAt(2);
1460-
array.removeAt(2);
1459+
array.splice(2, 1);
1460+
array.splice(2, 1);
14611461
set(this.context, 'model.shouldShow', false);
14621462
});
14631463

packages/@ember/-internals/glimmer/tests/integration/components/link-to/routing-angle-test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import {
55
runTask,
66
} from 'internal-test-helpers';
77
import Controller, { inject as injectController } from '@ember/controller';
8-
import { A as emberA } from '@ember/array';
98
import { RSVP } from '@ember/-internals/runtime';
109
import Route from '@ember/routing/route';
1110
import NoneLocation from '@ember/routing/none-location';
1211
import { service } from '@ember/service';
1312
import Engine from '@ember/engine';
1413
import { DEBUG } from '@glimmer/env';
1514
import { compile } from '../../../utils/helpers';
15+
import { tracked } from 'tracked-built-ins';
1616

1717
// IE includes the host name
1818
function normalizeUrl(url) {
@@ -1536,7 +1536,7 @@ moduleFor(
15361536
controller = this;
15371537
}
15381538

1539-
routeNames = emberA(['foo', 'bar', 'rar']);
1539+
routeNames = tracked(['foo', 'bar', 'rar']);
15401540
route1 = 'bar';
15411541
route2 = 'foo';
15421542
}
@@ -1579,7 +1579,7 @@ moduleFor(
15791579

15801580
linksEqual(this.$('a'), ['/foo', '/bar', '/rar', '/foo', '/bar', '/rar', '/rar', '/foo']);
15811581

1582-
runTask(() => controller.routeNames.shiftObject());
1582+
runTask(() => controller.routeNames.shift());
15831583

15841584
linksEqual(this.$('a'), ['/bar', '/rar', '/bar', '/rar', '/rar', '/foo']);
15851585
}

0 commit comments

Comments
 (0)