Since the arrival of Ember Octane we could start using native JavaScript classes.
And since the EmberJS community is awesome, it has created a ember-native-class-codemod to help out with the migration.
Sadly from the readme of the codemod:
Unsupported Types
While the codemods transforms many types of ember objects, it does not support transformation of
ember-data classes such as DS.Model, DS.Adapter etc
So my entire data layer has been left out. And thanks to superb backwards compatibility it was ok. But now the time has come to do something about it.
The solution I used is the cheapest I could come up with, but it's by no means bullet proof nor without the need of manual intervention. But it does a lot of the work.
It uses vscode global search&replace functionality:
Native class
Search
export default Model.extend\(\{((\n.*)*)\}\);
Replace with
export default class TooLazyToNameModel extends Model {$1};
@attr, @belongsTo, @hasMany
Search
(\w*): (attr|belongsTo|hasMany)\((.*)\),
Replace with
@$2($3) $1;
Conclusion
Hope these might help someone out. I know that for example multiline attribute definitions won't be covered. So please share in comments improved versions and I'm happy to update.
Photo by Franco Antonio Giovanella on Unsplash
Top comments (0)