From 11ac33ef0ae161850d3451895b22c5cdfddcc59f Mon Sep 17 00:00:00 2001 From: Chris Garrett Date: Thu, 31 Jan 2019 13:41:18 -0800 Subject: [PATCH 1/2] Adds aliasMethod deprecation --- content/ember/v3/deprecate-alias-method.md | 59 ++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 content/ember/v3/deprecate-alias-method.md diff --git a/content/ember/v3/deprecate-alias-method.md b/content/ember/v3/deprecate-alias-method.md new file mode 100644 index 00000000..0ee81302 --- /dev/null +++ b/content/ember/v3/deprecate-alias-method.md @@ -0,0 +1,59 @@ +--- +id: object.alias-method +title: Deprecate `@ember/object#aliasMethod` +until: '4.0.0' +since: '3.8' +--- + +`@ember/object#aliasMethod` is a little known and rarely used method that allows +user's to add aliases to objects defined with `EmberObject`: + +```js +import EmberObject, { aliasMethod } from '@ember/object'; + +export default EmberObject.extend({ + foo: 123, + bar() { + console.log(this.foo); + }, + baz: aliasMethod('bar'), +}); +``` + +This can be refactored into a shared utility function: + +```js +import EmberObject from '@ember/object'; + +function logFoo(obj) { + console.log(obj.foo); +} + +export default EmberObject.extend({ + foo: 123, + bar() { + logFoo(this); + }, + baz() { + logFoo(this); + }, +}); +``` + +Avoid defining methods directly on the class definition, since this will not +translate well into native class syntax in the future: + +```js +// Do not use this, this is an antipattern! 🛑 +import EmberObject from '@ember/object'; + +function logFoo() { + console.log(this.foo); +} + +export default EmberObject.extend({ + foo: 123, + bar: logFoo, + baz: logFoo, +}); +``` From 38649be2fc952926564a6bdf32a659658758efc4 Mon Sep 17 00:00:00 2001 From: Chris Garrett Date: Fri, 1 Feb 2019 14:06:11 -0800 Subject: [PATCH 2/2] update example --- content/ember/v3/deprecate-alias-method.md | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/content/ember/v3/deprecate-alias-method.md b/content/ember/v3/deprecate-alias-method.md index 0ee81302..b5af9bc0 100644 --- a/content/ember/v3/deprecate-alias-method.md +++ b/content/ember/v3/deprecate-alias-method.md @@ -20,22 +20,18 @@ export default EmberObject.extend({ }); ``` -This can be refactored into a shared utility function: +This can be refactored into having one function call the other directly: ```js import EmberObject from '@ember/object'; -function logFoo(obj) { - console.log(obj.foo); -} - export default EmberObject.extend({ foo: 123, bar() { - logFoo(this); + console.log(this.foo); }, baz() { - logFoo(this); + this.bar(...arguments); }, }); ```