-
-
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
Conversation
Aren't these used by Ember internally to convert camel case to kabobs case when resolving modules? |
|
IMHo is more important to get them off prototypes then it is to totally remove. |
|
||
The remaining methods (`htmlSafe` and `isHTMLSafe`) will be moved to `@ember/component`. | ||
|
||
In both cases, the String prototype won't be extended anymore. |
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:
In both cases, the String prototype won't be extended anymore by default.
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.
Yes? It will require a major version bump.
It would take quite some effort to audit and fix all the uses.
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.
You can almost do this with a regular expression, but a codemod can definitely be whipped up.
@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:
function do(something) {
return something.dasherize();
}
something
could be an instance of some class, having a dasherize
method completely unrelated to Ember.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.
I don't think the point of a codmod is really to eliminate all human review of code
@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.
Update on RFC based on feedback
Update on RFC
@ming-codes @btecu @joukevandermaas @simonihmig @bryanaka I have overhauled the RFC, can you review and let me know if it's clearer? |
We discussed this at the September 1 core team call. We are generally all in favor of this moving forward and decided to move this to final comment period. Thank you everyone for the comments, please review to make sure your concerns are addressed. |
@locks the rfc gives no reason why the htmlsafe functions should be moved. can you explain that part? |
I agree with @martletandco. Importing |
There is a pattern in Glimmer (and in many modern typesafe environments) to export public interfaces from the consumer of that interface. Applying that pattern here, it might make sense to move |
I like both @jamesarosen's and @Turbo87's ideas. @Turbo87's has an advantage: when/if routed templates are deprecated, the module does not need to be modified. |
Update 0000-deprecation-ember-string.md
My thoughts:
|
I actually landed here after checking out emberjs/ember.js#15626. My first thought was:
I don't see an explanation for that here, but I think the suggestion @Turbo87 made for imports such as |
Is there a namespace for template or rendering items? |
* Update 0000-deprecation-ember-string.md * Update 0000-deprecation-ember-string.md * Update 0000-deprecation-ember-string.md
|
||
In the specific case of `Ember.String`, our goal is that users that need who these utility functions will include `@ember/string` in their dependencies, or rely on common utility packages like [`lodash.camelcase`](https://lodash.com/docs/#camelCase). | ||
|
||
To achieve the above goal we will move the `isHTMLSafe`/`htmlSafe` pair into a new package, deprecate `String.prototype` extensions, and deprecate the utility functions under the `Ember.String` namespace. | ||
|
||
Thehe ["Organize by Mental Model"](https://github.com/emberjs/rfcs/blob/master/text/0176-javascript-module-api.md#organize-by-mental-model) section of RFC #176 mentions the concept of chunking. In the current setup, `isHTMLSafe`/`htmlSafe` make sense in the `Ember.String` namespace because they operate on strings, and they are available on the prototype, `"myString".htmlSafe()`. |
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.
Thehe seems like typo
Hey everyone, we have updated the RFC to address the concerns raised, namely the package where the HTML safe utilities should go. |
This RFC was discussed at a previous core meeting, and it seems the community is in agreement with how the concerns raised were resolved. Thanks for helping shape this RFC, time to . |
Advance RFC #236 to Stage Released
Advance RFC #236 "Ember.String deprecation RFC" to Stage Recommended
rendered