From ffb091e74b9b110b2e870126e159e48cff528c0e Mon Sep 17 00:00:00 2001 From: cibernox Date: Tue, 29 May 2018 11:49:51 +0200 Subject: [PATCH 1/6] RFC to deprecate `component#sendAction` --- text/0000-deprecate-send-action.md | 47 ++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 text/0000-deprecate-send-action.md diff --git a/text/0000-deprecate-send-action.md b/text/0000-deprecate-send-action.md new file mode 100644 index 0000000000..017fabcc9e --- /dev/null +++ b/text/0000-deprecate-send-action.md @@ -0,0 +1,47 @@ +- Start Date: 2019-05-29 +- RFC PR: (leave this empty) +- Ember Issue: (leave this empty) + +# Deprecate `.sendAction` + +## Summary + +In old versions of Ember (< 1.13) `component#sendAction` was the only way for a component to call an +action on a parent scope. In 1.13 with the so called _closure actions_ a more intuitive and flexible +way of calling actions was introduced, yielding the old way redundant. + +## Motivation + +With the new _closure actions_ being the recommended way, `component#sendAction` is not even +mentioned in the guides. +With the goal of simplifying the framework I think we should remove what is not considered the +current best practice. +_Closure actions_ have been available since 1.13. That is 3 years ago, so deprecating `sendAction` +should not cause too much pain and yet addons can support still support the last version of the 1.X +cycle if they really want to. + +## Detailed design + +A deprecation message will appear when `sendAction` is invoked. The feature will be removed in +Ember 4.0. The deprecation message will use the arguments passed to `sendAction` to generate a dynamic +explanation that will make super-easy for developers to migrate to closure actions. + +As it is mandatory with new deprecations, a new entry in the deprecation guides will be added +explaining the migration path in depth. + +## How we teach this + +There are no new concepts to teach, but the removal of an old concept now considered outdated. + +## Drawbacks + +There might be some churn following the deprecation, specially comming from addons that haven't been +updated in a while. +Addons that want to support the latest versions of Ember without deprecation messages and still work +past Ember 1.13 will have to do some gymnastics to do so. + +## Alternatives + +Wait longer to deprecate it and keep `sendAction` undocumented until it's usage is yet more minoritary +than it is today, to lower the churn. + From d08e81cb993d33bd9575e632c22bff5d517f088a Mon Sep 17 00:00:00 2001 From: Miguel Camba Date: Tue, 29 May 2018 14:27:03 +0200 Subject: [PATCH 2/6] Added link to blog post explaining closure actions --- text/0000-deprecate-send-action.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/text/0000-deprecate-send-action.md b/text/0000-deprecate-send-action.md index 017fabcc9e..3333b94668 100644 --- a/text/0000-deprecate-send-action.md +++ b/text/0000-deprecate-send-action.md @@ -20,6 +20,9 @@ _Closure actions_ have been available since 1.13. That is 3 years ago, so deprec should not cause too much pain and yet addons can support still support the last version of the 1.X cycle if they really want to. +It is out of the scope of this RFC to enumerate the reasons why _closure actions_ are preferred over +_sendAction_ but you can find an in depth explanation of _closure actions_ in [this blog post from 2016](http://miguelcamba.com/blog/2016/01/24/ember-closure-actions-in-depth). + ## Detailed design A deprecation message will appear when `sendAction` is invoked. The feature will be removed in From b22436507e52534d552de2acd249ccc38bf6f396 Mon Sep 17 00:00:00 2001 From: Miguel Camba Date: Tue, 29 May 2018 18:00:48 +0200 Subject: [PATCH 3/6] Add example migration --- text/0000-deprecate-send-action.md | 92 ++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/text/0000-deprecate-send-action.md b/text/0000-deprecate-send-action.md index 3333b94668..b2824223b2 100644 --- a/text/0000-deprecate-send-action.md +++ b/text/0000-deprecate-send-action.md @@ -32,6 +32,98 @@ explanation that will make super-easy for developers to migrate to closure actio As it is mandatory with new deprecations, a new entry in the deprecation guides will be added explaining the migration path in depth. +To refresh what the migration path would look like in the typical use case. + +**BEFORE** +```js +// parent-component.js +export default Component.extend({ + actions: { + sayHi() { + alert('Hello user!'); + } + } +}) +``` + +```hbs +{{!-- parent-component.hbs --}} +{{child-component salute="sayHi"}} +``` + +```js +// child-component.js +export default Component.extend({ + actions: { + sendSalute() { + this.sendAction('salute'); + } + } +}); +``` + +```hbs +{{!-- child-component.hbs --}} + +``` + +**AFTER** +```js +// parent-component.js +export default Component.extend({ + actions: { + sayHi() { + alert('Hello user!'); + } + } +}) +``` + +```hbs +{{!-- parent-component.hbs --}} +{{child-component salute=(action "sayHi")}} +``` + +```js +// child-component.js +export default Component.extend({ + actions: { + sendSalute() { + this.salute(); + } + } +}); +``` + +```hbs +{{!-- child-component.hbs --}} + +``` + +However _closure actions_ allow to be less verbose, so the same behavior could be attained using +less intermediate calls + +```js +// parent-component.js +export default Component.extend({ + actions: { + sayHi() { + alert('Hello user!'); + } + } +}) +``` + +```hbs +{{!-- parent-component.hbs --}} +{{child-component salute=(action "sayHi")}} +``` + +```hbs +{{!-- child-component.hbs --}} + +``` + ## How we teach this There are no new concepts to teach, but the removal of an old concept now considered outdated. From c71cfc01453ff7886e13b2bc5dbd1119ba9db119 Mon Sep 17 00:00:00 2001 From: Miguel Camba Date: Wed, 30 May 2018 00:03:27 +0200 Subject: [PATCH 4/6] Fix typo in date --- text/0000-deprecate-send-action.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/text/0000-deprecate-send-action.md b/text/0000-deprecate-send-action.md index b2824223b2..b5ce031f3e 100644 --- a/text/0000-deprecate-send-action.md +++ b/text/0000-deprecate-send-action.md @@ -1,4 +1,4 @@ -- Start Date: 2019-05-29 +- Start Date: 2018-05-29 - RFC PR: (leave this empty) - Ember Issue: (leave this empty) From b9d17f5e35f23a48edf1f81a76f3fe83bfe52e96 Mon Sep 17 00:00:00 2001 From: Miguel Camba Date: Fri, 1 Jun 2018 19:24:14 +0200 Subject: [PATCH 5/6] Add comment in case salute is not mandatory --- text/0000-deprecate-send-action.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/text/0000-deprecate-send-action.md b/text/0000-deprecate-send-action.md index b5ce031f3e..af49799a3b 100644 --- a/text/0000-deprecate-send-action.md +++ b/text/0000-deprecate-send-action.md @@ -90,6 +90,10 @@ export default Component.extend({ actions: { sendSalute() { this.salute(); + // if the salute action is optional you'll have to guard in case it's undefined: + // if (this.salute) { + // this.salute() + // } } } }); From 9d6311f4648c87765694208f0a967a05aafb6ed4 Mon Sep 17 00:00:00 2001 From: Miguel Andrade Date: Mon, 4 Jun 2018 14:54:04 +0100 Subject: [PATCH 6/6] Update 0000-deprecate-send-action.md --- text/0000-deprecate-send-action.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/text/0000-deprecate-send-action.md b/text/0000-deprecate-send-action.md index af49799a3b..414a1b05cf 100644 --- a/text/0000-deprecate-send-action.md +++ b/text/0000-deprecate-send-action.md @@ -94,6 +94,12 @@ export default Component.extend({ // if (this.salute) { // this.salute() // } + // + // Alternatively, you can also define a noop salute function: + // salute() {} + // + // This allows you to remove the guard while provinding an obvious place to add + // docs for that action. } } });