Skip to content

Commit 8845d5d

Browse files
committed
Kill reopenClass
1 parent 44589c5 commit 8845d5d

File tree

16 files changed

+25
-194
lines changed

16 files changed

+25
-194
lines changed

packages/@ember/-internals/container/tests/container_test.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -432,11 +432,9 @@ moduleFor(
432432
let Apple = factory();
433433
let Orange = factory();
434434

435-
Apple.reopenClass({
436-
_lazyInjections() {
437-
return [{ specifier: 'orange:main' }, { specifier: 'banana:main' }];
438-
},
439-
});
435+
Apple._lazyInjections = function () {
436+
return [{ specifier: 'orange:main' }, { specifier: 'banana:main' }];
437+
};
440438

441439
registry.register('apple:main', Apple);
442440
registry.register('orange:main', Orange);
@@ -459,12 +457,10 @@ moduleFor(
459457
let Apple = factory();
460458
let Orange = factory();
461459

462-
Apple.reopenClass({
463-
_lazyInjections: () => {
464-
assert.ok(true, 'should call lazy injection method');
465-
return [{ specifier: 'orange:main' }];
466-
},
467-
});
460+
Apple._lazyInjections = () => {
461+
assert.ok(true, 'should call lazy injection method');
462+
return [{ specifier: 'orange:main' }];
463+
};
468464

469465
registry.register('apple:main', Apple);
470466
registry.register('orange:main', Orange);

packages/@ember/-internals/glimmer/lib/component.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,7 @@ class Component<S = unknown>
10851085
@property positionalParams
10861086
@since 1.13.0
10871087
*/
1088-
declare static positionalParams: string | string[];
1088+
static positionalParams: string | string[];
10891089

10901090
/**
10911091
Layout can be used to wrap content in a component.
@@ -1596,11 +1596,6 @@ class Component<S = unknown>
15961596
}
15971597
}
15981598

1599-
// We continue to use reopenClass here so that positionalParams can be overridden with reopenClass in subclasses.
1600-
Component.reopenClass({
1601-
positionalParams: [],
1602-
});
1603-
16041599
setInternalComponentManager(CURLY_COMPONENT_MANAGER, Component);
16051600

16061601
export default Component;

packages/@ember/-internals/glimmer/lib/views/outlet.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ export default class OutletView {
3737
};
3838
}
3939

40-
static reopenClass(injections: any): void {
41-
Object.assign(this, injections);
42-
}
43-
4440
static create(options: {
4541
environment: BootEnvironment;
4642
application: InternalOwner;

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ moduleFor(
143143

144144
let instance;
145145
let FooBarComponent = class extends Component {
146+
static positionalParams = ['firstPositional'];
147+
146148
init() {
147149
super.init(...arguments);
148150
instance = this;
@@ -166,10 +168,6 @@ moduleFor(
166168
}
167169
};
168170

169-
FooBarComponent.reopenClass({
170-
positionalParams: ['firstPositional'],
171-
});
172-
173171
this.registerComponent('foo-bar', { ComponentClass: FooBarComponent });
174172

175173
this.render(`{{foo-bar this.firstPositional first=this.first second=this.second}}`, {

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,7 @@ moduleFor(
6262
return;
6363
}
6464

65-
let Thing = setComponentTemplate(
66-
compile('hello'),
67-
Component.extend().reopenClass({
68-
toString() {
69-
return 'Thing';
70-
},
71-
})
72-
);
65+
let Thing = setComponentTemplate(compile('hello'), Component.extend());
7366

7467
assert.throws(() => {
7568
setComponentTemplate(compile('foo'), Thing);

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3212,9 +3212,9 @@ moduleFor(
32123212

32133213
expectAssertion(() => {
32143214
this.registerComponent('foo-bar', {
3215-
ComponentClass: MyComponent.reopenClass({
3216-
positionalParams: ['myVar'],
3217-
}),
3215+
ComponentClass: class extends MyComponent {
3216+
static positionalParams = ['myVar'];
3217+
},
32183218
template:
32193219
'MyVar1: {{attrs.myVar}} {{this.myVar}} MyVar2: {{this.myVar2}} {{attrs.myVar2}}',
32203220
});
@@ -3227,9 +3227,9 @@ moduleFor(
32273227

32283228
expectDeprecation(() => {
32293229
this.registerComponent('foo-bar', {
3230-
ComponentClass: MyComponent.reopenClass({
3231-
positionalParams: ['myVar'],
3232-
}),
3230+
ComponentClass: class extends MyComponent {
3231+
static positionalParams = ['myVar'];
3232+
},
32333233
template:
32343234
'MyVar1: {{this.attrs.myVar}} {{this.myVar}} MyVar2: {{this.myVar2}} {{this.attrs.myVar2}}',
32353235
});
@@ -3244,9 +3244,9 @@ moduleFor(
32443244
let MyComponent = class extends Component {};
32453245

32463246
this.registerComponent('foo-bar', {
3247-
ComponentClass: MyComponent.reopenClass({
3248-
positionalParams: ['myVar'],
3249-
}),
3247+
ComponentClass: class extends MyComponent {
3248+
static positionalParams = ['myVar'];
3249+
},
32503250
template: 'MyVar1: {{@myVar}} {{this.myVar}} MyVar2: {{this.myVar2}} {{@myVar2}}',
32513251
});
32523252

packages/@ember/engine/index.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -551,10 +551,7 @@ export function buildInitializerMethod<
551551
// SAFETY: The superclass may be an Engine, we don't call unless we confirmed it was ok.
552552
let superclass = this.superclass as typeof Engine;
553553
if (superclass[bucketName] !== undefined && superclass[bucketName] === this[bucketName]) {
554-
let attrs = {
555-
[bucketName]: Object.create(this[bucketName]),
556-
};
557-
this.reopenClass(attrs);
554+
this[bucketName] = Object.create(this[bucketName]);
558555
}
559556

560557
assert(

packages/@ember/object/core.ts

Lines changed: 1 addition & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
DEBUG_INJECTION_FUNCTIONS,
1818
hasUnknownProperty,
1919
} from '@ember/-internals/metal';
20-
import Mixin, { applyMixin } from '@ember/object/mixin';
20+
import Mixin from '@ember/object/mixin';
2121
import makeArray from '@ember/array/make';
2222
import { assert } from '@ember/debug';
2323
import { DEBUG } from '@glimmer/env';
@@ -795,71 +795,6 @@ class CoreObject {
795795
return instance as InstanceType<C> & MergeArray<Args>;
796796
}
797797

798-
/**
799-
Augments a constructor's own properties and functions:
800-
801-
```javascript
802-
import EmberObject from '@ember/object';
803-
804-
const MyObject = EmberObject.extend({
805-
name: 'an object'
806-
});
807-
808-
MyObject.reopenClass({
809-
canBuild: false
810-
});
811-
812-
MyObject.canBuild; // false
813-
o = MyObject.create();
814-
```
815-
816-
In other words, this creates static properties and functions for the class.
817-
These are only available on the class and not on any instance of that class.
818-
819-
```javascript
820-
import EmberObject from '@ember/object';
821-
822-
const Person = EmberObject.extend({
823-
name: '',
824-
sayHello() {
825-
alert(`Hello. My name is ${this.get('name')}`);
826-
}
827-
});
828-
829-
Person.reopenClass({
830-
species: 'Homo sapiens',
831-
832-
createPerson(name) {
833-
return Person.create({ name });
834-
}
835-
});
836-
837-
let tom = Person.create({
838-
name: 'Tom Dale'
839-
});
840-
let yehuda = Person.createPerson('Yehuda Katz');
841-
842-
tom.sayHello(); // "Hello. My name is Tom Dale"
843-
yehuda.sayHello(); // "Hello. My name is Yehuda Katz"
844-
alert(Person.species); // "Homo sapiens"
845-
```
846-
847-
Note that `species` and `createPerson` are *not* valid on the `tom` and `yehuda`
848-
variables. They are only valid on `Person`.
849-
850-
@method reopenClass
851-
@for @ember/object
852-
@static
853-
@public
854-
*/
855-
static reopenClass<C extends typeof CoreObject>(
856-
this: C,
857-
...mixins: Array<Mixin | Record<string, unknown>>
858-
): C {
859-
applyMixin(this, mixins);
860-
return this;
861-
}
862-
863798
static detect(obj: unknown) {
864799
if ('function' !== typeof obj) {
865800
return false;

packages/@ember/object/mixin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ function updateObserversAndListeners(obj: object, key: string, fn: Function, add
393393
}
394394
}
395395

396-
export function applyMixin(
396+
function applyMixin(
397397
obj: Record<string, any>,
398398
mixins: Array<Mixin | Record<string, unknown>>,
399399
_hideKeys = false

packages/@ember/object/tests/extend_test.js

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { computed, get } from '@ember/object';
1+
import { computed } from '@ember/object';
22
import EmberObject, { observer } from '@ember/object';
33
import { moduleFor, AbstractTestCase, runLoopSettled } from 'internal-test-helpers';
44

@@ -92,36 +92,6 @@ moduleFor(
9292
);
9393
}
9494

95-
['@test With concatenatedProperties class properties'](assert) {
96-
let SomeClass = EmberObject.extend();
97-
SomeClass.reopenClass({
98-
concatenatedProperties: ['things'],
99-
things: 'foo',
100-
});
101-
let AnotherClass = SomeClass.extend();
102-
AnotherClass.reopenClass({ things: 'bar' });
103-
let YetAnotherClass = SomeClass.extend();
104-
YetAnotherClass.reopenClass({ things: 'baz' });
105-
let some = SomeClass.create();
106-
let another = AnotherClass.create();
107-
let yetAnother = YetAnotherClass.create();
108-
assert.deepEqual(
109-
get(some.constructor, 'things'),
110-
['foo'],
111-
'base class should have just its value'
112-
);
113-
assert.deepEqual(
114-
get(another.constructor, 'things'),
115-
['foo', 'bar'],
116-
"subclass should have base class' and its own"
117-
);
118-
assert.deepEqual(
119-
get(yetAnother.constructor, 'things'),
120-
['foo', 'baz'],
121-
"subclass should have base class' and its own"
122-
);
123-
}
124-
12595
async ['@test Overriding a computed property with an observer'](assert) {
12696
let Parent = EmberObject.extend({
12797
foo: computed(function () {

0 commit comments

Comments
 (0)