Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions content/ember/v7/deprecate-comparable-mixin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
title: Deprecate Comparable mixin
until: 7.5.0
since: 7.2.0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NullVoxPopuli did this actually land in 7.2?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It did, but it is also until 7.5 because it was private, so just an intimate api

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

---

The `Comparable` mixin is deprecated. This mixin was private but as it may have been intimate API, per our policy we've added a deprecation that will remain for at least one LTS.

Apps and addons should stop importing or extending `Comparable`. To provide custom comparison behavior, define a function-valued `compare(other)` method directly on the object or class instead.

Before:

```js
import EmberObject from '@ember/object';
import Comparable from '@ember/-internals/runtime/lib/mixins/comparable';

const Rectangle = EmberObject.extend(Comparable, {
compare(other) {
// custom comparison logic
},
});
```

After:

```js
class Rectangle {
// Returns -1, 0, 1
compare(other) {
// custom comparison logic
},
}
```

Defining `compare(other)` directly is sufficient.

However, if you need to `sort` a list of your objects, you will want to define a separate [`comparator function`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#description).
Loading