-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
dasherize ALL the things: use dasherized model names everywhere #3033
Conversation
e0238ad
to
8c97324
Compare
Tests fail? |
8c97324
to
f55aa4f
Compare
Yeah, I rebased without re running, fixed the tests that broke. They were expecting a camelCased type when extracting, but it should be dasherized. |
var key = type+":"+name; | ||
retrieveManagedInstance: function(typeKey, name) { | ||
var normalizedTypeKey = this._normalizeTypeKey(typeKey); | ||
var key = normalizedTypeKey +":"+name; |
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.
tiny nitpick: spaces around +
f55aa4f
to
ea09080
Compare
Can we add tests that assert this is backwards compatible? |
And by we, I meant the awesome @fivetanley :D |
var camelize = Ember.String.camelize; | ||
|
||
/** | ||
All typeKeys are camelCase internally. Changing this function may |
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.
camelCase => dasherized?
c77c090
to
c6de197
Compare
@return {String} if the adapter can generate one, an ID | ||
*/ | ||
export default function normalizeTypeKey(typeKey) { | ||
return singularize(dasherize(camelize(typeKey))); |
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.
Why do we have to singularize here?
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.
we don't have to, but it's nice
I am pretty scared of dasherizing typeKey, gonna break people's stuff a bunch. Maybe we should go with the modelName strategy? |
It'd be great to know what people are using typeKey for. Most of the changes in your app code would be comparing against dasherized strings. If we're going to remove this, I'd rather remove it this week than right before 1.0. |
Yeah, just takes more tedious work, but I can switch this over to that. |
I'm using typeKey in a handful of cases, specifically for some very hacky polymorhphic relationship handling. One example is the "attachable" polymorphic relationship. I have an action that updates the "attached" model when an image is removed from it. I use typeKey here (I'm sure there's a much better way to do this, but I just did a search in my project and that's where I'm using it):
|
return match.toLowerCase(); | ||
}).replace('::', '/'); | ||
return this._super(normalized); |
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.
If _super
is not RESTAdapter
the return would not be present. It is, seems ok, but is not safe if the parent class is not as expected.
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.
👍
25eca06
to
7de8109
Compare
d9609b0
to
153c4fd
Compare
@@ -25,7 +25,7 @@ function Snapshot(record) { | |||
this.id = get(record, 'id'); | |||
this.record = record; | |||
this.type = record.constructor; | |||
this.typeKey = record.constructor.typeKey; | |||
this.modelName = record.constructor.modelName; |
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.
needs deprecation
153c4fd
to
77a0d02
Compare
Previously, we allowed container keys to be loosy-goosy and normalized them in several places. This commit consolidates those efforts into one place `normalizeTypeKey`. typeKey is now referred to as modelName on snapshot instances and Model classes. typeKey remains on both of these but is deprecated. modelName is now a dasherized string, where previously it was camelCased.
77a0d02
to
61928c8
Compare
dasherize ALL the things: use dasherized model names everywhere
So this breaks everyone's apps that where |
@fivetanley I thought we kept the existing behavior for RestAdapter? None of the tests were changed |
@igorT looks like my app is customizing |
@raytiley kinda surprised it broke, would you mind sharing what the problem/fix was? |
I had this code which broke whith RESTAdapter.reopen({
pathForType: function(type) {
return Ember.String.pluralize(type.toLowerCase());
}
}); I changed it to RESTAdapter.reopen({
pathForType: function(type) {
var path = this._super(type);
return path.toLowerCase();
}
}); |
Closes emberjs#3969 This test has been obsolete since emberjs#3033
use dasherized model names everywhere / change typeKey -> modelName
Previously, we allowed container keys to be loosy-goosy and normalized
them in several places. This commit consolidates those efforts into
one place
normalizeTypeKey
.typeKey is now referred to as modelName on snapshot instances and Model
classes. typeKey remains on both of these but is deprecated.
modelName is now a dasherized string, where previously it was
camelCased.