Skip to content

Commit 4ee6f68

Browse files
committed
Kill reopenClass
1 parent c2167a8 commit 4ee6f68

File tree

16 files changed

+25
-205
lines changed

16 files changed

+25
-205
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
@@ -1103,7 +1103,7 @@ class Component<S = unknown>
11031103
@property positionalParams
11041104
@since 1.13.0
11051105
*/
1106-
declare static positionalParams: string | string[];
1106+
static positionalParams: string | string[];
11071107

11081108
/**
11091109
Layout can be used to wrap content in a component.
@@ -1614,11 +1614,6 @@ class Component<S = unknown>
16141614
}
16151615
}
16161616

1617-
// We continue to use reopenClass here so that positionalParams can be overridden with reopenClass in subclasses.
1618-
Component.reopenClass({
1619-
positionalParams: [],
1620-
});
1621-
16221617
setInternalComponentManager(CURLY_COMPONENT_MANAGER, Component);
16231618

16241619
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
@@ -3253,9 +3253,9 @@ moduleFor(
32533253

32543254
expectAssertion(() => {
32553255
this.registerComponent('foo-bar', {
3256-
ComponentClass: MyComponent.reopenClass({
3257-
positionalParams: ['myVar'],
3258-
}),
3256+
ComponentClass: class extends MyComponent {
3257+
static positionalParams = ['myVar'];
3258+
},
32593259
template:
32603260
'MyVar1: {{attrs.myVar}} {{this.myVar}} MyVar2: {{this.myVar2}} {{attrs.myVar2}}',
32613261
});
@@ -3268,9 +3268,9 @@ moduleFor(
32683268

32693269
expectDeprecation(() => {
32703270
this.registerComponent('foo-bar', {
3271-
ComponentClass: MyComponent.reopenClass({
3272-
positionalParams: ['myVar'],
3273-
}),
3271+
ComponentClass: class extends MyComponent {
3272+
static positionalParams = ['myVar'];
3273+
},
32743274
template:
32753275
'MyVar1: {{this.attrs.myVar}} {{this.myVar}} MyVar2: {{this.myVar2}} {{this.attrs.myVar2}}',
32763276
});
@@ -3285,9 +3285,9 @@ moduleFor(
32853285
let MyComponent = class extends Component {};
32863286

32873287
this.registerComponent('foo-bar', {
3288-
ComponentClass: MyComponent.reopenClass({
3289-
positionalParams: ['myVar'],
3290-
}),
3288+
ComponentClass: class extends MyComponent {
3289+
static positionalParams = ['myVar'];
3290+
},
32913291
template: 'MyVar1: {{@myVar}} {{this.myVar}} MyVar2: {{this.myVar2}} {{@myVar2}}',
32923292
});
32933293

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 & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ import {
1717
DEBUG_INJECTION_FUNCTIONS,
1818
hasUnknownProperty,
1919
} from '@ember/-internals/metal';
20-
import Mixin, { applyMixin } from '@ember/object/mixin';
21-
import { ActionHandler } from '@ember/-internals/runtime';
20+
import Mixin from '@ember/object/mixin';
2221
import makeArray from '@ember/array/make';
2322
import { assert } from '@ember/debug';
2423
import { DEBUG } from '@glimmer/env';
@@ -801,71 +800,6 @@ class CoreObject {
801800
return instance as InstanceType<C> & MergeArray<Args>;
802801
}
803802

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