Skip to content
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 20 commits into from
Sep 26, 2017
Merged

Conversation

Serabe
Copy link
Member

@Serabe Serabe commented Jul 19, 2017

@ming-codes
Copy link

Aren't these used by Ember internally to convert camel case to kabobs case when resolving modules?

@btecu
Copy link

btecu commented Jul 20, 2017

Ember data relies on those as well.

@stefanpenner
Copy link
Member

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.

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.

Copy link
Contributor

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.

Copy link
Contributor

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! ;)

Copy link

@bryanaka bryanaka Jul 26, 2017

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.

Copy link
Contributor

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.

@mmun mmun added T-framework RFCs that impact the ember.js library T-deprecation labels Aug 1, 2017
@locks
Copy link
Contributor

locks commented Aug 23, 2017

@ming-codes @btecu @joukevandermaas @simonihmig @bryanaka I have overhauled the RFC, can you review and let me know if it's clearer?

@locks
Copy link
Contributor

locks commented Sep 1, 2017

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.

@Turbo87
Copy link
Member

Turbo87 commented Sep 2, 2017

@locks the rfc gives no reason why the htmlsafe functions should be moved. can you explain that part?

@martletandco
Copy link

How does this impact helpers? htmlSafe and friends fall under templates rather than just components. You can import @ember/component into a helper but that shows it's a little off

Repeating comment here as requested

@Turbo87
Copy link
Member

Turbo87 commented Sep 4, 2017

I agree with @martletandco. Importing htmlSafe from @ember/component seems very unintuitive compared to @ember/string

@jamesarosen
Copy link

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 htmlSafe not to @ember/component but to the template layer. In the long run, @ember/component might be the primary way in which Ember applications interact with the template layer. Currently, however, those interactions are split between components and routed templates.

@Turbo87
Copy link
Member

Turbo87 commented Sep 6, 2017

I would like to propose moving the htmlSafe functions into a @ember/htmlsafe module instead of putting them in @ember/component to make the import seem a little bit more intuitive.

@locks @Serabe I'm still curious what the reasons are for wanting to move the functions out of @ember/string

@Serabe
Copy link
Member Author

Serabe commented Sep 6, 2017

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.

Julien Palmas and others added 2 commits September 7, 2017 09:14
@sandstrom
Copy link
Contributor

sandstrom commented Sep 7, 2017

My thoughts:

  • I agree with what others have said about @ember/component, it feels like an unintuitive place to move the functions.
  • Very happy to see loc deprecated! Its existence was confusing and it's insufficient for translations anyway.
  • Good idea to drop the string prototype extensions.

@alvincrespo
Copy link

alvincrespo commented Sep 10, 2017

I actually landed here after checking out emberjs/ember.js#15626. My first thought was:

Why is this going to be imported from @ember/component if the method names are related to Strings?

I don't see an explanation for that here, but I think the suggestion @Turbo87 made for imports such as @ember/htmlsafe makes the most sense. I think tightly coupling these "helpers" from the modules they are implemented in wouldn't be the most intuitive way. Just my 2 cents.

@martletandco
Copy link

Is there a namespace for template or rendering items? @ember/htmlSafe sets a trend of many small pieces to import. There should be some useful high level grouping

locks and others added 4 commits September 15, 2017 10:41
* 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()`.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thehe seems like typo

@locks
Copy link
Contributor

locks commented Sep 15, 2017

Hey everyone, we have updated the RFC to address the concerns raised, namely the package where the HTML safe utilities should go.
Please review the current proposal, we will have another round of FCP. If no further concern is raised, it should be merged next Friday.
Thank you for participating!

@locks
Copy link
Contributor

locks commented Sep 26, 2017

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 :shipit:.

@locks locks merged commit 1ece6ff into emberjs:master Sep 26, 2017
@locks locks deleted the deprecate-ember-string branch September 26, 2017 08:21
wagenet added a commit that referenced this pull request Jan 14, 2023
wagenet added a commit that referenced this pull request Apr 7, 2023
Advance RFC #236 "Ember.String deprecation RFC" to Stage Recommended
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Final Comment Period T-deprecation T-framework RFCs that impact the ember.js library
Projects
None yet
Development

Successfully merging this pull request may close these issues.