-
-
Notifications
You must be signed in to change notification settings - Fork 407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ember.String deprecation RFC #236
Merged
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
980b0e6
Ember.String deprecation RFC
Serabe 77f7305
Update on RFC
Serabe dcadbc1
Fix addon name
Serabe 7bd7e66
Merge pull request #1 from Serabe/update-on-rfc
Serabe 0cf1e6d
Update 0000-deprecation-ember-string.md
locks 2c11102
Update 0000-deprecation-ember-string.md
locks ff9b190
Update 0000-deprecation-ember-string.md
locks f467aa1
Update 0000-deprecation-ember-string.md
locks ecd06ab
Minor fixes
Serabe 51dfe48
Update 0000-deprecation-ember-string.md
locks 575aa50
Update 0000-deprecation-ember-string.md
locks 4d2f23b
Update 0000-deprecation-ember-string.md
4391801
Merge pull request #3 from bartocc/patch-2
Serabe a09d5f0
Update 0000-deprecation-ember-string.md (#2)
locks 8a1eab0
Update 0000-deprecation-ember-string.md
locks 762c9f8
Update 0000-deprecation-ember-string.md
locks 84c5131
Fix minor wording
Serabe 138ae8c
Update 0000-deprecation-ember-string.md
locks 06d4761
Remove last appearance of @ember/component
Serabe c1aea6b
rename RFC file
locks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
- Start Date: 2017-07-14 | ||
- RFC PR: (leave this empty) | ||
- Ember Issue: (leave this empty) | ||
|
||
# Summary | ||
|
||
This PR proposes the deprecation of `Ember.String`. The following methods will be moved to an addon: | ||
|
||
- `camelize` | ||
- `capitalize` | ||
- `classify` | ||
- `dasherize` | ||
- `decamelize` | ||
- `fmt` | ||
- `loc` | ||
- `underscore` | ||
- `w` | ||
|
||
The remaining methods (`htmlSafe` and `isHTMLSafe`) will be moved to `@ember/component`. | ||
|
||
In both cases, the String prototype won't be extended anymore. | ||
|
||
# Motivation | ||
|
||
`Ember.String` was introduced long ago, even before 1.0 was released. It was a time without the current ecosystem of addons. There were no ES6 modules, no Ember CLI and no Ember addons. Global mode was the way to go and prototypes of classes like `String`, `Array` and `Function` were being extended. | ||
|
||
A lot of nice-to-have functionality was added at that time but now Ember is lifting weight. These functions belong in an addon, where it can be maintained and evolve without being tied to the core of the framework. | ||
|
||
Also, this would let people swap the function for similar implementations but different behaviour in edge cases. | ||
|
||
Once most of the methods are moved to an addon and `String` is no longer being extended, makes more sense to move `htmlSafe` and `isHTMLSafe` methods to the component layer. | ||
|
||
|
||
# Transition Path | ||
|
||
Most methods will be extracted to an addon and will show a deprecation message when used from `Ember.String`. This way, if someone wants to use them, they just need to install an addon. | ||
|
||
For the last two, similar approach but moving them to the `@ember/component` module. | ||
|
||
# How We Teach This | ||
|
||
Ember guides' section on _disabling prototype extension_ would need to remove references to these methods. `camelize` is also used in the services tutorial. | ||
|
||
Main usage of these functions are in blueprints or connecting to APIs where converting the type of case of keys was needed. It is also used in Ember Data. | ||
|
||
Furthermore, when people have moved to the new shims, moving to an addon would be as easy as to change the import path. | ||
|
||
For `htmlSafe` and `isHTMLSafe`, the move is easier since the methods are easier related to components than to strings. | ||
|
||
In any case, a basic Ember Watson recipe would be easy to provide. | ||
|
||
# Drawbacks | ||
|
||
A lot of addons that deal with names depend on this behaviour, so they will need to install the addon. Also, Ember Data and some external serializers require these functions. | ||
|
||
`htmlSafe` and `isHTMLSafe` would need to change packages as well, thus the reason to try and provide an Ember Watson recipe. | ||
|
||
# Alternatives | ||
|
||
Leave things as they are. | ||
|
||
# Unresolved questions |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a pretty big breaking change. I know it's not great to extend prototypes but I know that at least our app pretty heavily relies on this. It would take quite some effort to audit and fix all the uses.
Perhaps this could be changed to:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes? It will require a major version bump.
You can almost do this with a regular expression, but a codemod can definitely be whipped up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@locks not so sure about this one. You can detect easily in a codemod a pattern like
'foo bar'.dasherize()
. But hard to reliable transform a variable where we don't know what type it is (string or not), like:something
could be an instance of some class, having adasherize
method completely unrelated toEmber.String
.So I think transforming your codebase could be a mainly manual step. Not saying that we shouldn't do this anyways! ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@simonihmig You bring up a good point, but just to bring a different perspective, I don't think the point of a codmod is really to eliminate all human review of code change, but rather to remove the tedious step of changing everything yourself.
Use it, commit where you are sure the mod is correct, and review places you are unsure about.
I'm with @joukevandermaas on this - I rather have this extend string by default, but throw deprecations (wrap methods in a deprecation when merging onto prototype). Perhaps have a feature flag to turn off the string prototype extension.
Right now there is a feature flag for extending prototypes in general, but maybe this RFC breaks string prototype into it's own feature flag. I think that makes sense, because in my mind, each group of prototype extensions exist for a very different reason. I see String extensions as utility, where as function extensions are syntactical sugar, and array functions were a mix of syntactical sugar and polyfilling new Array methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bryanaka Fully agree! But I think it should be quite conservative, in the sense that it may not convert everything, but for sure it won't do any harm, like making plain wrong transformations. Imagine a not so great test coverage, and wrong transformations are not detected, leading to real bugs...
I do think a codemod could add some real benefits when converting imports (new Ember Module API), or destructurings (
const { String: { dasherize } } = Ember;
) because they are easy to analyze statically. (See https://github.com/cibernox/ember-k-codemod). But I would question that a codemod would work well detecting the String prototype extensions, possibly doing more harm than adding value, as probably nobody writes'foo bar'.dasherize()
, so all use cases are comparable to the example given above (dasherize or any other method called on a variable rather than on a string literal) that you cannot reliably convert.So tl;dr yes, the prototype extensions can only be removed for Ember 3.0, and while we are on 2.x the deprecation notices should be used to refactor our code, where possible with a codemod, but I think also to a quite large extend manually.