Skip to content

[Next] Kill Ember Array and Mixins #20921

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions broccoli/amd-compat-entrypoints/ember.debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,12 @@ d('@ember/application/lib/lazy_load', emberApplicationLibLazyLoad);
import * as emberApplicationNamespace from '@ember/application/namespace';
d('@ember/application/namespace', emberApplicationNamespace);

import * as emberArrayinternals from '@ember/array/-internals';
d('@ember/array/-internals', emberArrayinternals);

import * as emberArrayIndex from '@ember/array/index';
d('@ember/array/index', emberArrayIndex);

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

import * as emberArrayMutable from '@ember/array/mutable';
d('@ember/array/mutable', emberArrayMutable);

import * as emberCanaryFeaturesIndex from '@ember/canary-features/index';
d('@ember/canary-features/index', emberCanaryFeaturesIndex);

Expand Down Expand Up @@ -230,9 +224,6 @@ d('@ember/object/internals', emberObjectInternals);
import * as emberObjectLibComputedComputedMacros from '@ember/object/lib/computed/computed_macros';
d('@ember/object/lib/computed/computed_macros', emberObjectLibComputedComputedMacros);

import * as emberObjectLibComputedReduceComputedMacros from '@ember/object/lib/computed/reduce_computed_macros';
d('@ember/object/lib/computed/reduce_computed_macros', emberObjectLibComputedReduceComputedMacros);

import * as emberObjectMixin from '@ember/object/mixin';
d('@ember/object/mixin', emberObjectMixin);

Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,14 @@
"ember-cli-typescript-blueprint-polyfill": "^0.1.0",
"ember-cli-version-checker": "^5.1.2",
"ember-router-generator": "^2.0.0",
"ember-tracked-storage-polyfill": "^1.0.0",
"inflection": "^2.0.1",
"route-recognizer": "^0.3.4",
"router_js": "^8.0.5",
"semver": "^7.5.2",
"silent-error": "^1.1.1",
"simple-html-tokenizer": "^0.5.11"
"simple-html-tokenizer": "^0.5.11",
"tracked-built-ins": "^4.0.0"
},
"devDependencies": {
"@aws-sdk/client-s3": "^3.731.0",
Expand Down Expand Up @@ -221,11 +223,9 @@
"@ember/application/instance.js": "ember-source/@ember/application/instance.js",
"@ember/application/lib/lazy_load.js": "ember-source/@ember/application/lib/lazy_load.js",
"@ember/application/namespace.js": "ember-source/@ember/application/namespace.js",
"@ember/array/-internals.js": "ember-source/@ember/array/-internals.js",
"@ember/array/index.js": "ember-source/@ember/array/index.js",
"@ember/array/lib/make-array.js": "ember-source/@ember/array/lib/make-array.js",
"@ember/array/make.js": "ember-source/@ember/array/make.js",
"@ember/array/mutable.js": "ember-source/@ember/array/mutable.js",
"@ember/canary-features/index.js": "ember-source/@ember/canary-features/index.js",
"@ember/component/helper.js": "ember-source/@ember/component/helper.js",
"@ember/component/index.js": "ember-source/@ember/component/index.js",
Expand Down Expand Up @@ -373,7 +373,8 @@
"ember/version.js": "ember-source/ember/version.js",
"route-recognizer/index.js": "ember-source/route-recognizer/index.js",
"router_js/index.js": "ember-source/router_js/index.js",
"rsvp/index.js": "ember-source/rsvp/index.js"
"rsvp/index.js": "ember-source/rsvp/index.js",
"tracked-built-ins/index.js": "ember-source/tracked-built-ins/index.js"
}
},
"typesVersions": {
Expand Down
22 changes: 1 addition & 21 deletions packages/@ember/-internals/glimmer/lib/utils/iterator.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import { objectAt } from '@ember/-internals/metal';
import type EmberArray from '@ember/array';
import { isEmberArray } from '@ember/array/-internals';
import { isObject } from '@ember/-internals/utils';
import type { Nullable } from '@ember/-internals/utility-types';
import type { IteratorDelegate } from '@glimmer/reference';
import { consumeTag, isTracking, tagFor } from '@glimmer/validator';
import { EachInWrapper } from '../helpers/each-in';
import type { NativeArray } from '@ember/array';

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

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

if (Array.isArray(iterable)) {
return ArrayIterator.from(iterable);
} else if (isEmberArray(iterable)) {
return EmberArrayIterator.from(iterable);
} else if (isNativeIterable(iterable)) {
return ArrayLikeNativeIterator.from(iterable);
} else if (hasForEach(iterable)) {
Expand Down Expand Up @@ -101,20 +95,6 @@ class ArrayIterator extends BoundedIterator {
}
}

class EmberArrayIterator extends BoundedIterator {
static from(iterable: EmberArray<unknown> | NativeArray<unknown>) {
return iterable.length > 0 ? new this(iterable) : null;
}

constructor(private array: EmberArray<unknown> | NativeArray<unknown>) {
super(array.length);
}

valueFor(position: number): unknown {
return objectAt(this.array as any, position);
}
}

class ObjectIterator extends BoundedIterator {
static fromIndexable(obj: Indexable) {
let keys = Object.keys(obj);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { moduleFor, RenderingTestCase, applyMixins, strip, runTask } from 'inter

import { isEmpty } from '@ember/utils';
import { action } from '@ember/object';
import { A as emberA } from '@ember/array';

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

import { tracked } from 'tracked-built-ins';

moduleFor(
'Components test: contextual components',
class extends RenderingTestCase {
Expand Down Expand Up @@ -1160,7 +1161,7 @@ moduleFor(
});

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

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

this.assertText('ab');

runTask(() => this.context.get('allParams').pushObject('c'));
runTask(() => this.context.get('allParams').push('c'));

this.assertText('abc');

runTask(() => this.context.get('allParams').popObject());
runTask(() => this.context.get('allParams').pop());

this.assertText('ab');

runTask(() => this.context.get('allParams').clear());
runTask(() => this.context.get('allParams').splice(0, 2));

this.assertText('');

runTask(() => this.context.set('allParams', emberA(['1', '2'])));
runTask(() => this.context.set('allParams', ['1', '2']));

this.assertText('12');

runTask(() => this.context.set('allParams', emberA(['a', 'b'])));
runTask(() => this.context.set('allParams', ['a', 'b']));

this.assertText('ab');
}
Expand All @@ -1201,7 +1202,7 @@ moduleFor(
this.render(
'{{#let (hash link=(component "my-link")) as |c|}}{{c.link params=this.allParams}}{{/let}}',
{
allParams: emberA(['a', 'b']),
allParams: tracked(['a', 'b']),
}
);

Expand All @@ -1211,23 +1212,23 @@ moduleFor(

this.assertText('ab');

runTask(() => this.context.get('allParams').pushObject('c'));
runTask(() => this.context.get('allParams').push('c'));

this.assertText('abc');

runTask(() => this.context.get('allParams').popObject());
runTask(() => this.context.get('allParams').pop());

this.assertText('ab');

runTask(() => this.context.get('allParams').clear());
runTask(() => this.context.get('allParams').splice(0, 3));

this.assertText('');

runTask(() => this.context.set('allParams', emberA(['1', '2'])));
runTask(() => this.context.set('allParams', ['1', '2']));

this.assertText('12');

runTask(() => this.context.set('allParams', emberA(['a', 'b'])));
runTask(() => this.context.set('allParams', ['a', 'b']));

this.assertText('ab');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ import {
runLoopSettled,
} from 'internal-test-helpers';

import { tracked as trackedBuiltIn } from 'tracked-built-ins';

import { action } from '@ember/object';
import { run } from '@ember/runloop';
import { DEBUG } from '@glimmer/env';
import { tracked } from '@ember/-internals/metal';
import { alias } from '@ember/object/computed';
import Service, { service } from '@ember/service';
import EmberObject, { set, get, computed, observer } from '@ember/object';
import { A as emberA } from '@ember/array';

import { Component, compile, htmlSafe } from '../../utils/helpers';
import { backtrackingMessageFor } from '../../utils/debug-stack';
Expand Down Expand Up @@ -1704,7 +1705,7 @@ moduleFor(
});

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

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

this.assertText('Foo4Bar');

runTask(() => this.context.get('things').pushObject(5));
runTask(() => this.context.get('things').push(5));

this.assertText('Foo4Bar5');

runTask(() => this.context.get('things').shiftObject());
runTask(() => this.context.get('things').shift());

this.assertText('4Bar5');

runTask(() => this.context.get('things').clear());
runTask(() => this.context.get('things').splice(0, 3));

this.assertText('');

runTask(() => this.context.set('things', emberA(['Foo', 4, 'Bar'])));
runTask(() => this.context.set('things', ['Foo', 4, 'Bar']));

this.assertText('Foo4Bar');
}
Expand Down Expand Up @@ -2563,7 +2564,7 @@ moduleFor(
template: 'Child: {{this.item}}.',
});

let items = emberA(['Tom', 'Dick', 'Harry']);
let items = trackedBuiltIn(['Tom', 'Dick', 'Harry']);

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

Expand All @@ -2573,15 +2574,15 @@ moduleFor(

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

runTask(() => this.context.get('items').pushObject('Sergio'));
runTask(() => this.context.get('items').push('Sergio'));

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

runTask(() => this.context.get('items').shiftObject());
runTask(() => this.context.get('items').shift());

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

runTask(() => this.context.set('items', emberA(['Tom', 'Dick', 'Harry'])));
runTask(() => this.context.set('items', ['Tom', 'Dick', 'Harry']));

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

init() {
super.init(...arguments);
this.options = emberA([]);
this.options = [];
this.value = null;
}

Expand All @@ -3017,11 +3018,16 @@ moduleFor(
}

registerOption(option) {
this.get('options').addObject(option);
if (this.get('options').indexOf(option) === -1) {
this.get('options').push(option);
}
}

unregisterOption(option) {
this.get('options').removeObject(option);
let index = this.get('options').indexOf(option);
if (index > -1) {
this.get('options').splice(index, 1);
}

this.updateValue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { classes, moduleFor, RenderingTestCase, runTask, strip } from 'internal-

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

import { Component } from '../../utils/helpers';
import { tracked } from 'tracked-built-ins';

class LifeCycleHooksTest extends RenderingTestCase {
constructor() {
Expand Down Expand Up @@ -1433,7 +1433,7 @@ moduleFor(
template: NestedTemplate,
});

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

this.render(
strip`
Expand All @@ -1456,8 +1456,8 @@ moduleFor(
this.assertText('1AB2AB3AB4AB5AB6AB7AB');

runTask(() => {
array.removeAt(2);
array.removeAt(2);
array.splice(2, 1);
array.splice(2, 1);
set(this.context, 'model.shouldShow', false);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import {
runTask,
} from 'internal-test-helpers';
import Controller, { inject as injectController } from '@ember/controller';
import { A as emberA } from '@ember/array';
import { RSVP } from '@ember/-internals/runtime';
import Route from '@ember/routing/route';
import NoneLocation from '@ember/routing/none-location';
import { service } from '@ember/service';
import Engine from '@ember/engine';
import { DEBUG } from '@glimmer/env';
import { compile } from '../../../utils/helpers';
import { tracked } from 'tracked-built-ins';

// IE includes the host name
function normalizeUrl(url) {
Expand Down Expand Up @@ -1536,7 +1536,7 @@ moduleFor(
controller = this;
}

routeNames = emberA(['foo', 'bar', 'rar']);
routeNames = tracked(['foo', 'bar', 'rar']);
route1 = 'bar';
route2 = 'foo';
}
Expand Down Expand Up @@ -1579,7 +1579,7 @@ moduleFor(

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

runTask(() => controller.routeNames.shiftObject());
runTask(() => controller.routeNames.shift());

linksEqual(this.$('a'), ['/bar', '/rar', '/bar', '/rar', '/rar', '/foo']);
}
Expand Down
Loading