Skip to content

Commit 26f9724

Browse files
Merge pull request #21577 from emberjs/nvp/deprecate-mixin-support
Deprecate mixins
2 parents b3a07fe + fdb1a7a commit 26f9724

41 files changed

Lines changed: 761 additions & 330 deletions

Some content is hidden

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

‎packages/@ember/-internals/deprecations/index.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ export const DEPRECATIONS = {
133133
until: '8.0.0',
134134
url: 'https://deprecations.emberjs.com/id/deprecate-evented',
135135
}),
136+
DEPRECATE_MIXINS: deprecation({
137+
id: 'deprecate-mixins',
138+
for: 'ember-source',
139+
since: { available: '7.4.0' },
140+
until: '8.0.0',
141+
url: 'https://deprecations.emberjs.com/id/deprecate-mixins',
142+
}),
136143
};
137144

138145
export function deprecateUntil(message: string, deprecation: DeprecationObject) {

‎packages/@ember/-internals/glimmer/tests/integration/components/target-action-test.js‎

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
} from 'internal-test-helpers';
88

99
import { action, set } from '@ember/object';
10-
import Mixin from '@ember/object/mixin';
1110
import Controller from '@ember/controller';
1211
import EmberObject from '@ember/object';
1312
import { DEPRECATIONS } from '@ember/-internals/deprecations';
@@ -149,18 +148,16 @@ moduleFor(
149148
}
150149
};
151150

152-
let BarViewMixin = Mixin.create({
153-
actions: {
154-
bar(msg) {
155-
assert.equal(msg, 'HELLO');
156-
this._super(msg);
157-
},
158-
},
159-
});
160-
161151
this.owner.register(
162152
'component:x-index',
163-
class extends SuperComponent.extend(BarViewMixin) {
153+
class extends SuperComponent.extend({
154+
actions: {
155+
bar(msg) {
156+
assert.equal(msg, 'HELLO');
157+
this._super(msg);
158+
},
159+
},
160+
}) {
164161
init() {
165162
super.init(...arguments);
166163
component = this;

‎packages/@ember/-internals/metal/tests/accessors/get_test.js‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ENV } from '@ember/-internals/environment';
22
import EmberObject, { observer } from '@ember/object';
33
import { get } from '../..';
4-
import Mixin from '@ember/object/mixin';
4+
import { mixin } from '@ember/object/mixin';
55
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
66
import { run } from '@ember/runloop';
77
import { destroy } from '@glimmer/destroyable';
@@ -187,12 +187,13 @@ moduleFor(
187187
['@test (regression) watched properties on unmodified inherited objects should still return their original value'](
188188
assert
189189
) {
190-
let MyMixin = Mixin.create({
191-
someProperty: 'foo',
192-
propertyDidChange: observer('someProperty', () => {}),
193-
});
194-
195-
let baseObject = MyMixin.apply({});
190+
let baseObject = mixin(
191+
{},
192+
{
193+
someProperty: 'foo',
194+
propertyDidChange: observer('someProperty', () => {}),
195+
}
196+
);
196197
let theRealObject = Object.create(baseObject);
197198

198199
assert.equal(

‎packages/@ember/-internals/metal/tests/events_test.js‎

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -141,26 +141,35 @@ moduleFor(
141141
}
142142

143143
[`${testUnless(
144-
DEPRECATIONS.DEPRECATE_EVENTED.isRemoved
144+
DEPRECATIONS.DEPRECATE_EVENTED.isRemoved || DEPRECATIONS.DEPRECATE_MIXINS.isRemoved
145145
)} @test a listener can be added as part of a mixin`](assert) {
146146
let triggered = 0;
147-
let MyMixin;
147+
let props;
148148
expectDeprecation(
149149
() => {
150-
MyMixin = Mixin.create({
150+
props = {
151151
foo1: on('bar', function () {
152152
triggered++;
153153
}),
154154

155155
foo2: on('bar', function () {
156156
triggered++;
157157
}),
158-
});
158+
};
159159
},
160160
/`on\(\)` event decorator is deprecated/,
161161
DEPRECATIONS.DEPRECATE_EVENTED.isEnabled
162162
);
163163

164+
let MyMixin;
165+
expectDeprecation(
166+
() => {
167+
MyMixin = Mixin.create(props);
168+
},
169+
/Using mixins is deprecated/,
170+
DEPRECATIONS.DEPRECATE_MIXINS.isEnabled
171+
);
172+
164173
let obj = {};
165174
MyMixin.apply(obj);
166175

@@ -197,35 +206,53 @@ moduleFor(
197206
}
198207

199208
[`${testUnless(
200-
DEPRECATIONS.DEPRECATE_EVENTED.isRemoved
209+
DEPRECATIONS.DEPRECATE_EVENTED.isRemoved || DEPRECATIONS.DEPRECATE_MIXINS.isRemoved
201210
)} @test a listener added as part of a mixin may be overridden`](assert) {
202211
let triggered = 0;
203-
let FirstMixin;
212+
let FirstProps;
204213
expectDeprecation(
205214
() => {
206-
FirstMixin = Mixin.create({
215+
FirstProps = {
207216
foo: on('bar', function () {
208217
triggered++;
209218
}),
210-
});
219+
};
211220
},
212221
/`on\(\)` event decorator is deprecated/,
213222
DEPRECATIONS.DEPRECATE_EVENTED.isEnabled
214223
);
215224

216-
let SecondMixin;
225+
let FirstMixin;
217226
expectDeprecation(
218227
() => {
219-
SecondMixin = Mixin.create({
228+
FirstMixin = Mixin.create(FirstProps);
229+
},
230+
/Using mixins is deprecated/,
231+
DEPRECATIONS.DEPRECATE_MIXINS.isEnabled
232+
);
233+
234+
let SecondProps;
235+
expectDeprecation(
236+
() => {
237+
SecondProps = {
220238
foo: on('baz', function () {
221239
triggered++;
222240
}),
223-
});
241+
};
224242
},
225243
/`on\(\)` event decorator is deprecated/,
226244
DEPRECATIONS.DEPRECATE_EVENTED.isEnabled
227245
);
228246

247+
let SecondMixin;
248+
expectDeprecation(
249+
() => {
250+
SecondMixin = Mixin.create(SecondProps);
251+
},
252+
/Using mixins is deprecated/,
253+
DEPRECATIONS.DEPRECATE_MIXINS.isEnabled
254+
);
255+
229256
let obj = {};
230257
FirstMixin.apply(obj);
231258
SecondMixin.apply(obj);

‎packages/@ember/-internals/metal/tests/mixin/apply_test.js‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
import { get } from '@ember/object';
22
import Mixin, { mixin } from '@ember/object/mixin';
3-
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
3+
import { moduleFor, AbstractTestCase, expectDeprecation, testUnless } from 'internal-test-helpers';
4+
import { DEPRECATIONS } from '../../../deprecations';
45

56
function K() {}
67

78
moduleFor(
89
'Mixin.apply',
910
class extends AbstractTestCase {
10-
['@test using apply() should apply properties'](assert) {
11+
[`${testUnless(DEPRECATIONS.DEPRECATE_MIXINS.isRemoved)} @test using apply() should apply properties`](
12+
assert
13+
) {
14+
expectDeprecation(/Using mixins is deprecated/, DEPRECATIONS.DEPRECATE_MIXINS.isEnabled);
15+
1116
let MixinA = Mixin.create({ foo: 'FOO', baz: K });
1217
let obj = {};
1318
mixin(obj, MixinA);

‎packages/@ember/-internals/metal/tests/namespace_search_test.js‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import Mixin from '@ember/object/mixin';
2-
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
2+
import { moduleFor, AbstractTestCase, expectDeprecation, testUnless } from 'internal-test-helpers';
3+
import { DEPRECATIONS } from '../../deprecations';
34

45
moduleFor(
56
'NamespaceSearch',
67
class extends AbstractTestCase {
7-
['@test classToString: null as this inside class must not throw error'](assert) {
8+
[`${testUnless(DEPRECATIONS.DEPRECATE_MIXINS.isRemoved)} @test classToString: null as this inside class must not throw error`](
9+
assert
10+
) {
11+
expectDeprecation(/Using mixins is deprecated/, DEPRECATIONS.DEPRECATE_MIXINS.isEnabled);
12+
813
let mixin = Mixin.create();
914
assert.equal(
1015
mixin.toString(),

0 commit comments

Comments
 (0)