From c87fb082338f9706e2f94d65d4fdcea3ccd7aa78 Mon Sep 17 00:00:00 2001 From: Sarup Banskota Date: Thu, 8 Feb 2018 00:24:11 +0800 Subject: [PATCH 1/6] Deprecate function.prototype.{on, property, observes} --- ...on-native-function-prototype-extensions.md | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 text/000-deprecation-native-function-prototype-extensions.md diff --git a/text/000-deprecation-native-function-prototype-extensions.md b/text/000-deprecation-native-function-prototype-extensions.md new file mode 100644 index 0000000000..8b608663fb --- /dev/null +++ b/text/000-deprecation-native-function-prototype-extensions.md @@ -0,0 +1,63 @@ +- Start Date: 2017-11-20 +- RFC PR: +- Ember Issue: + +# Summary + +This RFC proposes to deprecate `Function.prototype.on`, +`Function.proptotype.observes` and `Function.prototype.property` + +# Motivation + +Ember has been moving away from extending native prototypes due to the confusion +that this causes users: is it specifically part of Ember, or JavaScript? + +Continuing in that direction, we should consider recommending the usage of +`Ember.on` `Ember.observer` and `Ember.computed` as opposed to their native +prototype extension equivalents. We go from two ways to do something, to one. + + +[`eslint-plugin-ember` already provides this as a rule](https://github.com/ember-cli/eslint-plugin-ember/blob/master/docs/rules/no-function-prototype-extensions.md). + +# Transition Path + +The replacement functionality already exists in the form of `Ember.{on, observer, computed}`. +We don't need to build anything new specifically, however the bulk of the transition will be +focused on deprecating the native prototype extensions. + +Borrowing from the [ESLint plugin example](https://github.com/ember-cli/eslint-plugin-ember/blob/master/docs/rules/no-function-prototype-extensions.md): + +```js +import { computed, observer } from '@ember/object'; +import { on } from '@ember/object/evented'; + +export default Component.extend({ + // current + abc: function() { /* custom logic */ }.property('xyz'), + def: function() { /* custom logic */ }.observe('xyz'), + ghi: function() { /* custom logic */ }.on('didInsertElement'), + + // proposed + abc: computed('xyz', function() { /* custom logic */ }), + def: observer('xyz', function() { /* custom logic */ }), + ghi: on('didInsertElement', function() { /* custom logic */ }), +}); +``` + +We need to create a codemod that will transform code from the `current` form to the +`proposed` form. + +# How We Teach This + +On the deprecation guide, we showcase the same example as above. We can explain why +the proposal was necessary, followed by a `deprecated / current` snippet. + +The Ember guides currently discourages the use of Function prototype extensions. +For example, from the [disabling prototype extensions page](https://guides.emberjs.com/v2.17.0/configuring-ember/disabling-prototype-extensions/): + +After the deprecated code is removed from Ember, the same page needs to remove the section +about `Function` prototypes altogether. + +# Alternatives + +Leave things as is. From a7b424662bbd8488a694da011dc4601fe939824e Mon Sep 17 00:00:00 2001 From: Ricardo Mendes Date: Mon, 12 Feb 2018 23:14:36 +0000 Subject: [PATCH 2/6] Update 000-deprecation-native-function-prototype-extensions.md --- ...ion-native-function-prototype-extensions.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/text/000-deprecation-native-function-prototype-extensions.md b/text/000-deprecation-native-function-prototype-extensions.md index 8b608663fb..c080b1fb9f 100644 --- a/text/000-deprecation-native-function-prototype-extensions.md +++ b/text/000-deprecation-native-function-prototype-extensions.md @@ -1,5 +1,5 @@ - Start Date: 2017-11-20 -- RFC PR: +- RFC PR: https://github.com/emberjs/rfcs/pull/272 - Ember Issue: # Summary @@ -13,16 +13,16 @@ Ember has been moving away from extending native prototypes due to the confusion that this causes users: is it specifically part of Ember, or JavaScript? Continuing in that direction, we should consider recommending the usage of -`Ember.on` `Ember.observer` and `Ember.computed` as opposed to their native -prototype extension equivalents. We go from two ways to do something, to one. - +[`on` (`@ember/object/evented`)](https://emberjs.com/api/ember/2.18/classes/@ember%2Fobject%2Fevented/methods/on?anchor=on), [`observer` (`@ember/object`)](https://emberjs.com/api/ember/2.18/classes/@ember%2Fobject/methods/observer?anchor=observer) and [`computed` (`@ember/object`)](https://emberjs.com/api/ember/2.18/classes/@ember%2Fobject/methods/computed?anchor=computed) as opposed to their native +prototype extension equivalents. +We go from two ways to do something, to one. [`eslint-plugin-ember` already provides this as a rule](https://github.com/ember-cli/eslint-plugin-ember/blob/master/docs/rules/no-function-prototype-extensions.md). # Transition Path -The replacement functionality already exists in the form of `Ember.{on, observer, computed}`. -We don't need to build anything new specifically, however the bulk of the transition will be +The replacement functionality already exists in the form of `on`, `observer`, and `computed`. +We don't need to build anything new specifically, however, the bulk of the transition will be focused on deprecating the native prototype extensions. Borrowing from the [ESLint plugin example](https://github.com/ember-cli/eslint-plugin-ember/blob/master/docs/rules/no-function-prototype-extensions.md): @@ -50,9 +50,9 @@ We need to create a codemod that will transform code from the `current` form to # How We Teach This On the deprecation guide, we showcase the same example as above. We can explain why -the proposal was necessary, followed by a `deprecated / current` snippet. +the proposal was necessary, followed by deprecated to current code examples. -The Ember guides currently discourages the use of Function prototype extensions. +The Guides currently discourage the use of `Function` prototype extensions. For example, from the [disabling prototype extensions page](https://guides.emberjs.com/v2.17.0/configuring-ember/disabling-prototype-extensions/): After the deprecated code is removed from Ember, the same page needs to remove the section @@ -60,4 +60,4 @@ about `Function` prototypes altogether. # Alternatives -Leave things as is. +None. From 4e125152450ee9399ebaec16eb557553b02b438c Mon Sep 17 00:00:00 2001 From: Ricardo Mendes Date: Mon, 12 Feb 2018 23:16:08 +0000 Subject: [PATCH 3/6] Update 000-deprecation-native-function-prototype-extensions.md --- text/000-deprecation-native-function-prototype-extensions.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/text/000-deprecation-native-function-prototype-extensions.md b/text/000-deprecation-native-function-prototype-extensions.md index c080b1fb9f..38bfc8d1ae 100644 --- a/text/000-deprecation-native-function-prototype-extensions.md +++ b/text/000-deprecation-native-function-prototype-extensions.md @@ -2,10 +2,12 @@ - RFC PR: https://github.com/emberjs/rfcs/pull/272 - Ember Issue: +# Deprecate Function.prototype.on, Function.prototype.observes and Function.prototype.property + # Summary This RFC proposes to deprecate `Function.prototype.on`, -`Function.proptotype.observes` and `Function.prototype.property` +`Function.prototype.observes` and `Function.prototype.property` # Motivation From 16bd92ec965d9b2f4984f8535199dcd333616b7e Mon Sep 17 00:00:00 2001 From: Ricardo Mendes Date: Mon, 12 Feb 2018 23:17:37 +0000 Subject: [PATCH 4/6] Update 000-deprecation-native-function-prototype-extensions.md --- ...deprecation-native-function-prototype-extensions.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/text/000-deprecation-native-function-prototype-extensions.md b/text/000-deprecation-native-function-prototype-extensions.md index 38bfc8d1ae..ac2996b3b9 100644 --- a/text/000-deprecation-native-function-prototype-extensions.md +++ b/text/000-deprecation-native-function-prototype-extensions.md @@ -4,12 +4,12 @@ # Deprecate Function.prototype.on, Function.prototype.observes and Function.prototype.property -# Summary +## Summary This RFC proposes to deprecate `Function.prototype.on`, `Function.prototype.observes` and `Function.prototype.property` -# Motivation +## Motivation Ember has been moving away from extending native prototypes due to the confusion that this causes users: is it specifically part of Ember, or JavaScript? @@ -21,7 +21,7 @@ We go from two ways to do something, to one. [`eslint-plugin-ember` already provides this as a rule](https://github.com/ember-cli/eslint-plugin-ember/blob/master/docs/rules/no-function-prototype-extensions.md). -# Transition Path +## Transition Path The replacement functionality already exists in the form of `on`, `observer`, and `computed`. We don't need to build anything new specifically, however, the bulk of the transition will be @@ -49,7 +49,7 @@ export default Component.extend({ We need to create a codemod that will transform code from the `current` form to the `proposed` form. -# How We Teach This +## How We Teach This On the deprecation guide, we showcase the same example as above. We can explain why the proposal was necessary, followed by deprecated to current code examples. @@ -60,6 +60,6 @@ For example, from the [disabling prototype extensions page](https://guides.ember After the deprecated code is removed from Ember, the same page needs to remove the section about `Function` prototypes altogether. -# Alternatives +## Alternatives None. From d79e5a43b6aade1d584c0b4f8ff5bf2c948106ac Mon Sep 17 00:00:00 2001 From: Sarup Banskota Date: Wed, 14 Feb 2018 16:06:29 +0800 Subject: [PATCH 5/6] Move sections around --- ...on-native-function-prototype-extensions.md | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/text/000-deprecation-native-function-prototype-extensions.md b/text/000-deprecation-native-function-prototype-extensions.md index ac2996b3b9..dd106bef28 100644 --- a/text/000-deprecation-native-function-prototype-extensions.md +++ b/text/000-deprecation-native-function-prototype-extensions.md @@ -27,6 +27,15 @@ The replacement functionality already exists in the form of `on`, `observer`, an We don't need to build anything new specifically, however, the bulk of the transition will be focused on deprecating the native prototype extensions. +We need to create a codemod that will transform code from the `deprecated` form to the +`proposed` form. + +## How We Teach This + +On the deprecation guide, we can showcase the same example as above. We can explain why +the proposal was necessary, followed by a set of examples highlighting the deprecated +vs current style. + Borrowing from the [ESLint plugin example](https://github.com/ember-cli/eslint-plugin-ember/blob/master/docs/rules/no-function-prototype-extensions.md): ```js @@ -34,30 +43,25 @@ import { computed, observer } from '@ember/object'; import { on } from '@ember/object/evented'; export default Component.extend({ - // current + // deprecated abc: function() { /* custom logic */ }.property('xyz'), def: function() { /* custom logic */ }.observe('xyz'), ghi: function() { /* custom logic */ }.on('didInsertElement'), - // proposed + // current abc: computed('xyz', function() { /* custom logic */ }), def: observer('xyz', function() { /* custom logic */ }), ghi: on('didInsertElement', function() { /* custom logic */ }), }); ``` -We need to create a codemod that will transform code from the `current` form to the -`proposed` form. - -## How We Teach This - -On the deprecation guide, we showcase the same example as above. We can explain why -the proposal was necessary, followed by deprecated to current code examples. +[The Guides currently discourage the use of `Function` prototype extensions](https://guides.emberjs.com/v2.17.0/configuring-ember/disabling-prototype-extensions/): -The Guides currently discourage the use of `Function` prototype extensions. -For example, from the [disabling prototype extensions page](https://guides.emberjs.com/v2.17.0/configuring-ember/disabling-prototype-extensions/): +> Function is extended with methods to annotate functions as computed properties, +> via the property() method, and as observers, via the observes() method. Use of +> these methods is now discouraged and not covered in recent versions of the Guides. -After the deprecated code is removed from Ember, the same page needs to remove the section +After the deprecated code is removed from Ember, we need to remove the section about `Function` prototypes altogether. ## Alternatives From 573afbad239771d3e2fcd1c7ce10e75f9d96fcc1 Mon Sep 17 00:00:00 2001 From: Ricardo Mendes Date: Tue, 20 Feb 2018 09:34:02 +0000 Subject: [PATCH 6/6] Small tweaks to the prose --- ...precation-native-function-prototype-extensions.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/text/000-deprecation-native-function-prototype-extensions.md b/text/000-deprecation-native-function-prototype-extensions.md index dd106bef28..11630c8635 100644 --- a/text/000-deprecation-native-function-prototype-extensions.md +++ b/text/000-deprecation-native-function-prototype-extensions.md @@ -24,11 +24,11 @@ We go from two ways to do something, to one. ## Transition Path The replacement functionality already exists in the form of `on`, `observer`, and `computed`. + We don't need to build anything new specifically, however, the bulk of the transition will be focused on deprecating the native prototype extensions. -We need to create a codemod that will transform code from the `deprecated` form to the -`proposed` form. +A codemod for this deprecation has to take into consideration that while `foo: function() { /* custom logic */ }.property('bar')` is a `Function.prototype` extension, `foo: observer(function () { /* some custom logic */ }).on('customEvent')` is not. ## How We Teach This @@ -46,16 +46,18 @@ export default Component.extend({ // deprecated abc: function() { /* custom logic */ }.property('xyz'), def: function() { /* custom logic */ }.observe('xyz'), - ghi: function() { /* custom logic */ }.on('didInsertElement'), +  ghi: function() { /* custom logic */ }.on('didInsertElement'), +  jkl: function() { /* custom logic */ }.on('customEvent'), // current abc: computed('xyz', function() { /* custom logic */ }), def: observer('xyz', function() { /* custom logic */ }), - ghi: on('didInsertElement', function() { /* custom logic */ }), + didInsertElement() { /* custom logic */ }), + jkl: on('customEvent', function() { /* custom logic */ }), }); ``` -[The Guides currently discourage the use of `Function` prototype extensions](https://guides.emberjs.com/v2.17.0/configuring-ember/disabling-prototype-extensions/): +The official Guides currently [discourage the use of `Function.prototype` extensions](https://guides.emberjs.com/v2.17.0/configuring-ember/disabling-prototype-extensions/): > Function is extended with methods to annotate functions as computed properties, > via the property() method, and as observers, via the observes() method. Use of