Skip to content

Commit

Permalink
Merge pull request #948 from Glarregle/main
Browse files Browse the repository at this point in the history
Deprecation guide Ember.Component.reopen
  • Loading branch information
jenweber authored Sep 8, 2021
2 parents 0a87f8e + 91c9412 commit b1ce3b7
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions content/ember/v4/ember-component-reopen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
id: ember.component.reopen
title: Reopening Classic Component Super Class
until: '5.0.0'
since: '4.0.0'
---

Reopening the `Ember.Component` super class has far-reaching consequences. For example, it may unexpectedly break addons that are not expecting the changes.

To respond to DOM events globally, consider instead using global event listeners.

Before:
``` javascript
import Component from '@ember/component';

Component.reopen({
click() {
console.log('Clicked on a classic component');
}
});
```


After:
``` javascript
document.addEventListener('click', event => {
if (event.target.classList.contains('my-component')) {
console.log('Clicked on a classic component');
}
});
```


Alternatively, you can create a custom subclass of `Ember.Component` with the behavior you want and subclass from that component in your app. That way, only those components which explicitly opted into the changes will be affected.

Before:
``` javascript
import Component from '@ember/component';

Component.reopen({
attributeBindings: ['metadata:data-my-metadata'],
metadata: ''
});
```


After:
``` javascript
// app/components/base.js
import Component from '@ember/component';

// Subclass from this in your app, instead of subclassing from Ember.Component
export default Component.extend({
attributeBindings: ['metadata:data-my-metadata'],
metadata: ''
});
```

0 comments on commit b1ce3b7

Please sign in to comment.