From 7e91a0547b87b94cd4865bc99f6e872434a6807f Mon Sep 17 00:00:00 2001 From: Peter Wagenet Date: Fri, 20 Jun 2025 16:17:49 -0700 Subject: [PATCH 1/2] Add Mixin deprecation guide --- content/ember/v6/deprecate-ember-mixin.md | 74 +++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 content/ember/v6/deprecate-ember-mixin.md diff --git a/content/ember/v6/deprecate-ember-mixin.md b/content/ember/v6/deprecate-ember-mixin.md new file mode 100644 index 00000000..36c3b1ea --- /dev/null +++ b/content/ember/v6/deprecate-ember-mixin.md @@ -0,0 +1,74 @@ +--- +title: Deprecating Ember.Mixin +until: 7.0.0 +since: 6.5.0 +--- + +`Ember.Mixin` is deprecated. This is part of the legacy `@ember/object` API and is not fully compatible with native classes. Instead of using mixins, you should refactor your code to use class-based patterns. + +One common pattern to replace mixins is to use class decorators. + +### Before: Using Mixins + +Here is an example of a mixin that provides "editable" functionality to a class: + +```javascript +// app/mixins/editable.js +import Mixin from '@ember/object/mixin'; + +export default Mixin.create({ + isEditing: false, + + edit() { + console.log('starting to edit'); + this.set('isEditing', true); + }, +}); +``` + +```javascript +// app/models/comment.js +import EmberObject from '@ember/object'; +import EditableMixin from '../mixins/editable'; + +export default class Comment extends EmberObject.extend(EditableMixin) { + post = null; +} +``` + +### After: Using Class Decorators + +You can achieve the same result by creating a class decorator. This decorator will add the same properties and methods to the class it's applied to. + +First, create the decorator function: + +```javascript +// app/decorators/editable.js +import { tracked } from '@glimmer/tracking'; + +export function editable(klass) { + return class extends klass { + @tracked isEditing = false; + + edit() { + console.log('starting to edit'); + this.isEditing = true; + } + }; +} +``` + +Then, apply the decorator to your class: + +```javascript +// app/models/comment.js +import EmberObject from '@ember/object'; +import { editable } from '../decorators/editable'; + +@editable +export default class Comment extends EmberObject { + post = null; +} +``` + +This approach provides the same functionality as the mixin but uses standard JavaScript features, making the code easier to understand and maintain. From 3c19ecdcd4df42526699a8f521fedeee0176f1f6 Mon Sep 17 00:00:00 2001 From: Peter Wagenet Date: Mon, 23 Jun 2025 09:30:29 -0700 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> --- content/ember/v6/deprecate-ember-mixin.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/content/ember/v6/deprecate-ember-mixin.md b/content/ember/v6/deprecate-ember-mixin.md index 36c3b1ea..1e4f302d 100644 --- a/content/ember/v6/deprecate-ember-mixin.md +++ b/content/ember/v6/deprecate-ember-mixin.md @@ -4,7 +4,7 @@ until: 7.0.0 since: 6.5.0 --- -`Ember.Mixin` is deprecated. This is part of the legacy `@ember/object` API and is not fully compatible with native classes. Instead of using mixins, you should refactor your code to use class-based patterns. +`Ember.Mixin` is deprecated. This is part of the legacy `@ember/object` API and is not compatible with native classes. Instead of using mixins, you should refactor your code to use class-based patterns. One common pattern to replace mixins is to use class decorators. @@ -71,4 +71,4 @@ export default class Comment extends EmberObject { } ``` -This approach provides the same functionality as the mixin but uses standard JavaScript features, making the code easier to understand and maintain. +This approach provides the same functionality as the mixin but uses standard JavaScript features, making the code easier to understand.