-
-
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
Update blueprints to use native JS classes #5859
Conversation
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.
LGTM, may need future tweaks to make this work better, but this lets us begin the iteration process....
I would like to get rid of the param What are other changes came to your mind? |
Not sure, I kinda want to get this in and start testing in apps to see what crops up... |
Isn't this mixing syntaxes or am I misreading these in some way? For instance, it looks like this might generate the following in some cases:
|
😱 , Yes, you are right. I should have thought about the ED decorators case. I have seen the
|
@pzuraq probably has the best insights for whether these blueprints should
|
Happy to give context where I can!
|
blueprints/model/index.js
Outdated
|
||
if (/has-many|belongs-to/.test(dasherizedType)) { | ||
needs.push("'model:" + dasherizedForeignModelSingular + "'"); | ||
} | ||
} | ||
|
||
let attrTransformer, attrSeparator; | ||
if (process.env.EMBER_VERSION === 'OCTANE') { |
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 could create a util function under lib/utilities
to detect OCTANE
. This function could be in the same module than lib/utilities/module-unification
and this could be renamed to env-detector.js
.
I would prefer to do this change in a follow-up PR and based on the reviewer instructions.
00759ab
to
de18443
Compare
I think this PR is ready now; the Model blueprint can generate attr decorators and this behavior is validated on the tests.
I tested one case of the |
Tested this on a new app by running import DS from 'ember-data';
const { Model } = DS;
export default class UserModel extends Model {
@DS.attr('string') firstName;
@DS.attr('string') lastName;
@DS.attr('number') age
} Shouldn't the last attribute have a semicolon? |
de18443
to
61eefe1
Compare
@efx Thank you for testing and reporting. I have included the fix and it'll generate: import DS from 'ember-data';
const { Model } = DS;
export default class UserModel extends Model {
@DS.attr('string') firstName;
@DS.attr('string') lastName;
@DS.attr('number') age;
} |
@ppcano in keeping with import DS from 'ember-data';
const { Model, attr } = DS;
export default class UserModel extends Model {
@attr('string')
firstName;
@attr('string')
lastName;
@attr('number')
age;
} |
@runspired Yes, I can work on these changes. Just to double check:
instead of
I lean toward the second. |
@ppcano while I prefer the second, |
Prettier has changed its stance on this, checkout this demo in the playground. |
14f557a
to
394da8e
Compare
@runspired The Model blueprint syntax has been improved. Now, it will generate: // Octane apps
import DS from 'ember-data';
const { Model, attr } = DS;
export default class UserModel extends Model {
@attr('string') firstName;
@attr('string') lastName;
@attr('number') age;
} // Classic apps
import DS from 'ember-data';
const { Model, attr } = DS;
export default Model.extend({
firstName: attr('string'),
lastName: attr('string'),
age: attr('number')
}); Let me know if Classic apps should continue using the |
@ppcano this looks amazing! Is it in good shape for |
@runspired Yes, |
Part of the Octane Tracking issue.
Atm, the blueprints will only generate Native Classes if the env
EMBER_VERSION
is equal toOCTANE
; the octane-blueprints will set the variable.It follows the same implementation than the Ember repo emberjs/ember.js#17621