Skip to content

Commit f9f4815

Browse files
authored
Merge pull request #241 from salsify/deprecate-classic-component-apis
2 parents 9b50f79 + 1d621d2 commit f9f4815

File tree

3 files changed

+68
-6
lines changed

3 files changed

+68
-6
lines changed

CHANGELOG.md

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,50 @@
1-
## 1.4.0 (May 17, 2021)
1+
## Unreleased
2+
### Deprecated
3+
- ECM's support for binding local class names on the root element of a classic `Ember.Compnent` (the `localClassNames` and `localClassNameBindings` properties and the `@localClassName` and `@localClassNames` decorators) has been deprecated and will be removed in the next major release. These APIs rely on reopening `Ember.Component` (which is itself [now deprecated](https://github.com/emberjs/rfcs/pull/671)) and can be replaced by several alternative patterns. See the Upgrade Notes section below for migration suggestions.
4+
5+
### Upgrade Notes
6+
For classic `@ember/component` subclasses, `ember-css-modules` has had support for binding static and dynamic local class names to the component's root element using either `.extend()` or decorator syntax:
7+
8+
```js
9+
export default Component.extend({
10+
localClassNames: ['always-present'],
11+
localClassNameBindings: ['flipACoin'],
12+
13+
flipACoin: computed(function() {
14+
return Math.random() > 0.5 ? 'yes-class' : 'no-class';
15+
}),
16+
});
17+
```
18+
19+
```js
20+
@localClassNames('always-present')
21+
export default class MyComponent extends Component {
22+
@localClassName flipACoin = Math.random() > 0.5 ? 'yes-class' : 'no-class';
23+
}
24+
```
25+
26+
Both versions of these APIs are now deprecated, as:
27+
1. they rely on monkey-patching `Ember.Component`, which is itself [now deprecated](https://github.com/emberjs/rfcs/pull/671)
28+
1. they're parallels of the `classNames` and `classNameBindings` APIs that are no longer relevant in modern Ember applications
29+
30+
Depending on your appetite for refactoring and modernizing, you might take one of three approaches to migrating off of these APIs:
31+
1. Convert your components to use the modern `@glimmer/component` base class instead of `@ember/component`. Since Glimmer component templates have "outer HTML" semantics, there's no implicit root element for these APIs to apply to. See the [Octane vs Classic cheat sheet](https://ember-learn.github.io/ember-octane-vs-classic-cheat-sheet/) for further details on the differences between classic and Glimmer components.
32+
1. Use `tagName: ''` to remove the implicit root element from your classic component, then add a corresponding explicit root element to your template, where you can use `local-class` as you would for any other element.
33+
1. Import the class name mapping from your styles module and use that with the classic `classNames` and `classNameBindings` APIs:
34+
```js
35+
import styles from './styles';
36+
37+
export default Component.extend({
38+
classNames: [styles['always-present']],
39+
classNameBindings: ['flipACoin'],
40+
41+
flipACoin: computed(function() {
42+
return Math.random() > 0.5 ? styles['yes-class'] : styles['no-class'];
43+
}),
44+
});
45+
```
46+
47+
## 1.4.0 (May 17, 2021)
248
### Added
349
- We now support a wider range of dependencies that includes PostCSS 8 out of the box. Depending on your package manager, you'll likely see this upgrade take effect automatically when you update ECM, and you may see deprecation warnings for any older PostCSS plugins you're using.
450

packages/ember-css-modules/addon/mixins/component-mixin.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { computed, defineProperty } from '@ember/object';
44
import Mixin from '@ember/object/mixin';
55
import { dasherize } from '@ember/string';
66
import { getOwner } from '@ember/application';
7-
import { assert } from '@ember/debug';
7+
import { assert, deprecate } from '@ember/debug';
88

99
export default Mixin.create({
1010
localClassNames: null,
@@ -42,6 +42,22 @@ export default Mixin.create({
4242
layout
4343
);
4444

45+
deprecate(
46+
'Support for `localClassNames`, `localClassNameBindings` and the `@localClassName` and `@localClassNames` ' +
47+
'decorators will be removed in the next major release of ember-css-modules. The `' + name + '` component ' +
48+
'uses one or more of these APIs. See the ECM 1.5.0 release notes for further details and migration options: ' +
49+
'https://github.com/salsify/ember-css-modules/releases/tag/v1.5.0',
50+
false,
51+
{
52+
id: 'ember-css-modules.classic-component-apis',
53+
for: 'ember-css-modules',
54+
until: '2.0.0',
55+
since: {
56+
enabled: '1.5.0'
57+
}
58+
}
59+
);
60+
4561
// Since https://github.com/emberjs/ember.js/pull/18096
4662
if (typeof layout === 'function') layout = layout(getOwner(this));
4763

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6621,7 +6621,7 @@ ember-compatibility-helpers@^1.0.2, ember-compatibility-helpers@^1.1.1, ember-co
66216621
semver "^5.4.1"
66226622

66236623
"ember-css-modules@link:packages/ember-css-modules":
6624-
version "1.3.4"
6624+
version "1.4.0"
66256625
dependencies:
66266626
broccoli-bridge "^1.0.0"
66276627
broccoli-concat "^3.2.2"
@@ -6860,9 +6860,9 @@ ember-resolver@^8.0.2:
68606860
resolve "^1.17.0"
68616861

68626862
ember-rfc176-data@^0.3.12, ember-rfc176-data@^0.3.15, ember-rfc176-data@^0.3.16, ember-rfc176-data@^0.3.5:
6863-
version "0.3.16"
6864-
resolved "https://registry.yarnpkg.com/ember-rfc176-data/-/ember-rfc176-data-0.3.16.tgz#2ace0ac9cf9016d493a74a1d931643a308679803"
6865-
integrity sha512-IYAzffS90r2ybAcx8c2qprYfkxa70G+/UPkxMN1hw55DU5S2aLOX6v3umKDZItoRhrvZMCnzwsdfKSrKdC9Wbg==
6863+
version "0.3.17"
6864+
resolved "https://registry.yarnpkg.com/ember-rfc176-data/-/ember-rfc176-data-0.3.17.tgz#d4fc6c33abd6ef7b3440c107a28e04417b49860a"
6865+
integrity sha512-EVzTTKqxv9FZbEh6Ktw56YyWRAA0MijKvl7H8C06wVF+8f/cRRz3dXxa4nkwjzyVwx4rzKGuIGq77hxJAQhWWw==
68666866

68676867
ember-router-generator@^1.2.3:
68686868
version "1.2.3"

0 commit comments

Comments
 (0)