Skip to content
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

[CLEANUP beta] Remove Ember.Component.reopen #19831

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
62 changes: 2 additions & 60 deletions packages/@ember/-internals/glimmer/lib/component.ts
@@ -1,6 +1,6 @@
import { get, PROPERTY_DID_CHANGE } from '@ember/-internals/metal';
import { getOwner } from '@ember/-internals/owner';
import { CoreObject, TargetActionSupport } from '@ember/-internals/runtime';
import { TargetActionSupport } from '@ember/-internals/runtime';
import {
ActionSupport,
ChildViewsSupport,
Expand All @@ -12,7 +12,7 @@ import {
ViewStateSupport,
} from '@ember/-internals/views';
import { EMBER_MODERNIZED_BUILT_IN_COMPONENTS } from '@ember/canary-features';
import { assert, deprecate } from '@ember/debug';
import { assert } from '@ember/debug';
import { DEBUG } from '@glimmer/env';
import { Environment } from '@glimmer/interfaces';
import { setInternalComponentManager } from '@glimmer/manager';
Expand Down Expand Up @@ -1051,64 +1051,6 @@ if (EMBER_MODERNIZED_BUILT_IN_COMPONENTS) {
writable: true,
value: false,
});

Object.defineProperty(Component, 'reopen', {
configurable: true,
enumerable: false,
writable: true,
value: function reopen(this: typeof Component, ...args: unknown[]): unknown {
if (this === Component) {
deprecate(
'Reopening the Ember.Component super class itself is deprecated. ' +
'Consider alternatives such as installing event listeners on ' +
'the document or add the customizations to specific subclasses.',
false,
{
id: 'ember.component.reopen',
for: 'ember-source',
since: {
enabled: '3.27.0',
},
url: 'https://deprecations.emberjs.com/v3.x#toc_ember-component-reopen',
until: '4.0.0',
}
);

Component._wasReopened = true;
}

return CoreObject.reopen.call(this, ...args);
},
});

Object.defineProperty(Component, 'reopenClass', {
configurable: true,
enumerable: false,
writable: true,
value: function reopenClass(this: typeof Component, ...args: unknown[]): unknown {
if (this === Component) {
deprecate(
'Reopening the Ember.Component super class itself is deprecated. ' +
'Consider alternatives such as installing event listeners on ' +
'the document or add the customizations to specific subclasses.',
false,
{
id: 'ember.component.reopen',
for: 'ember-source',
url: 'https://deprecations.emberjs.com/v3.x#toc_ember-component-reopen',
since: {
enabled: '3.27.0',
},
until: '4.0.0',
}
);

Component._wasReopened = true;
}

return CoreObject.reopenClass.call(this, ...args);
},
});
}

export default Component;
@@ -1,10 +1,7 @@
import { moduleFor, RenderingTestCase, runDestroy, runTask } from 'internal-test-helpers';
import { EMBER_MODERNIZED_BUILT_IN_COMPONENTS } from '@ember/canary-features';
import { action } from '@ember/object';
import { Checkbox, TextArea, TextField } from '@ember/-internals/glimmer';
import { set } from '@ember/-internals/metal';
import { TargetActionSupport } from '@ember/-internals/runtime';
import { getElementView, TextSupport } from '@ember/-internals/views';

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

Expand Down Expand Up @@ -1321,137 +1318,3 @@ function InputAttributesTest(attrs) {
}
);
});

if (EMBER_MODERNIZED_BUILT_IN_COMPONENTS) {
[
['Ember.Component', Component, true, true],
['Ember.Checkbox', Checkbox, true, false],
['Ember.TextArea', TextArea, false, true],
['Ember.TextField', TextField, true, false],
['Ember.TextSupport', TextSupport, true, true],
['Ember.TargetActionSupport', TargetActionSupport, true, true],
].forEach(([label, ClassOrMixin, shouldDeoptInput, shouldDeoptTextArea]) => {
let message =
ClassOrMixin === Component
? /Reopening the Ember\.Component super class itself is deprecated\./
: new RegExp(`Reopening ${label.replace(/\./g, '\\.')} is deprecated\\.`);

class DeoptTest extends RenderingTestCase {
constructor() {
super(...arguments);
this.assertDidNotReopen();
}

teardown() {
super.teardown();
ClassOrMixin._wasReopened = false;
}

assertDidReopen() {
this.assert.strictEqual(ClassOrMixin._wasReopened, true, `${label} was marked as reopened`);
}

assertDidNotReopen() {
this.assert.strictEqual(
ClassOrMixin._wasReopened,
false,
`${label} was not marked as reopened`
);
}

assertDeopt(
_shouldDeoptInput = shouldDeoptInput,
_shouldDeoptTextArea = shouldDeoptTextArea
) {
this.render(`
<Input id="test-textbox" @value="hello" />
<Input id="test-checkbox" @type="checkbox" @checked={{true}} />
<Textarea id="test-textarea" @value="hello world" />
`);

let textbox = this.$('#test-textbox')[0];
let checkbox = this.$('#test-checkbox')[0];
let textarea = this.$('#test-textarea')[0];

this.assert.ok(textbox, 'a textbox was rendered');
this.assert.ok(checkbox, 'a checkbox was rendered');
this.assert.ok(textarea, 'a textarea was rendered');

this.assert.strictEqual(
this.isDeopted(textbox),
_shouldDeoptInput,
`<Input @type="text" /> ${_shouldDeoptInput ? 'was' : 'was not'} deopted`
);

this.assert.strictEqual(
this.isDeopted(checkbox),
_shouldDeoptInput,
`<Input @type="checkbox" /> ${_shouldDeoptInput ? 'was' : 'was not'} deopted`
);

this.assert.strictEqual(
this.isDeopted(textarea),
_shouldDeoptTextArea,
`<Textarea /> ${_shouldDeoptTextArea ? 'was' : 'was not'} deopted`
);
}

isDeopted(element) {
return getElementView(element) !== null;
}

[`@test ${label}.reopen()`]() {
expectDeprecation(
() =>
ClassOrMixin.reopen({
/* noop */
}),
message
);

this.assertDidReopen();
this.assertDeopt();
}
}

if (typeof ClassOrMixin.extend === 'function') {
DeoptTest.prototype[`@test ${label}.extend().reopen()`] = function () {
ClassOrMixin.extend().reopen({
/* noop */
});

this.assertDidNotReopen();
this.assertDeopt(false, false);
};
}

if (typeof ClassOrMixin.reopenClass === 'function') {
DeoptTest.prototype[`@test ${label}.reopenClass()`] = function () {
expectDeprecation(
() =>
ClassOrMixin.reopenClass({
/* noop */
}),
message
);

this.assertDidReopen();
this.assertDeopt();
};

DeoptTest.prototype[`@test ${label}.extend().reopenClass()`] = function () {
ClassOrMixin.extend().reopenClass({
/* noop */
});

this.assertDidNotReopen();
this.assertDeopt(false, false);
};
}

moduleFor(
`Components test: [DEPRECATED] <Input /> and <Textarea /> deopt (${label})`,
DeoptTest
);
});
}