@@ -25,11 +25,43 @@ lighter.
2525## Detailed design
2626
2727For the most part, this is a 1:1 substitution of the global ` console ` object
28- for ` Ember.Logger ` . However, Node only added support for ` console.debug ` in
29- Node version 9. If we wish to support earlier versions of Node, our codemod
30- will need to use ` console.log ` , rather than ` console.debug ` , as the
31- replacement for ` Logger.debug ` . For users who don't care about Node or are
32- specifying Node version 9 as their minimum, we could use ` console.debug ` .
28+ for ` Ember.Logger ` .
29+
30+ Node only added support for ` console.debug ` in Node version 9. Where we wish
31+ to support earlier versions of Node, we will need to use ` console.log ` , rather than
32+ ` console.debug ` , as the replacement for ` Logger.debug ` . Apps and addons
33+ which don't care about Node or are specifying Node version 9 as their minimum can
34+ use ` console.debug ` .
35+
36+ Internet Explorer 11 and Edge both require console methods to be bound to the
37+ console object when the developer tools are not showing. This diverges from the
38+ expectations of other browsers. Direct calls to console methods will work correctly,
39+ but constructs which involve explicitly or implicitly binding the console methods to
40+ other objects or using them unbound will fail. This is straightforward to work around.
41+
42+ You can address the issue by binding the method to the console object:
43+
44+ ``` javascript
45+ // Before - assigning raw method to a variable for later use
46+ var print = Logger .log ; // assigning method to variable
47+ print (' Message' );
48+
49+ // After - assigning console-bound method to variable for later use
50+ var print = console .log .bind (console );
51+ print (' Message' );
52+ ```
53+
54+ In some cases, you can use rest parameter syntax to avoid the issue entirely:
55+
56+ ``` javascript
57+ // Before
58+ Logger .info .apply (undefined , arguments ); // or
59+ Logger .info .apply (null , arguments ); // or
60+ Logger .info .apply (this , arguments ); // or
61+
62+ // After
63+ console .info (... arguments );
64+ ```
3365
3466### Within the framework
3567
@@ -72,24 +104,17 @@ currently consumes `Ember.Logger`, _not_ by `Ember.Logger` itself. Hence,
72104replacing calls to ` Ember.Logger ` with direct calls to the console will not
73105affect this behavior.
74106
75- ### Codemod
76-
77- Provide a codemod that developers can use to switch references to the methods
78- of ` Ember.Logger ` to use the corresponding ` console ` methods instead.
79-
80- The codemod will need to replace ` Ember.Logger.debug ` calls with `(console.debug ||
81- console.log)(<arguments >)` or something similar to take in stride the situation
82- where console.debug isn't defined.
83-
84- I will definitely need help here.
85-
86107### Add-On Developers
87108
88109The following high-impact add-ons (9 or 10 or a * on EmberObserver) use
89110` Ember.Logger ` and should probably be given an early heads-up to adjust
90111their code to use ` console ` before this RFC is implemented. This will limit
91112the level of pain that their users experience when the deprecation is released.
92113
114+ Add-ons that need to also support Ember 2.x will need to make their console
115+ references conditional on console being "truthy", of course, to support Internet
116+ Explorer 9.
117+
93118In the order of their number of references to ` Ember.Logger ` :
94119
95120* ` ember-concurrency ` (15)
@@ -129,10 +154,10 @@ Once it is gone from the code, we also need to verify it no longer appears in
129154the API listings.
130155
131156We must provide an entry in the deprecation guide for this change:
132- * offering instruction for using the codemod to perform the change automatically
133- with before and after code samples .
134- * describing the issue with using console.debug on node versions
135- earlier than Node 9 and what provision the codemod has made to deal with it .
157+ * describing relevant divergences remaining in the handling of the console in
158+ Internet Explorer 11 and Edge browsers .
159+ * describing the issue with using console.debug on node versions
160+ earlier than Node 9.
136161* describing alternative ways of dealing with eslint's ` no-console ` messages.
137162
138163## Drawbacks
@@ -143,9 +168,8 @@ on many projects.
143168
144169This, of course, can be said for almost any deprecation, and Ember's
145170disciplined approach to deprecation has been repeatedly shown to ease things.
146- Providing a codemod to replace ` Ember.Logger ` calls with the corresponding
147- console calls should make this transition relatively painless. Also, only
148- twenty of those add-ons have more than six references to ` Ember.Logger ` .
171+ These particular changes are proving easy to locate and replace by hand. Also,
172+ only twenty of those add-ons have more than six references to ` Ember.Logger ` .
149173If this is characteristic of the user base, the level of effort to make
150174the change, even by hand, should be very small for most users.
151175
0 commit comments