During ember 1 computed properties were written using function prototype extensions e.g.
...
fullName: function() {
return `${this.firstName} ${this.lastName}`;
}.property('firstName', 'lastName'),
...
This code mod will update the old .property()
syntax to the computed
syntax used in ember 2 & 3.
npx ember2-x-codemods property-to-computed path/of/files/ or/some**/*glob.js
# or
yarn global add ember2-x-codemods
ember2-x-codemods property-to-computed path/of/files/ or/some**/*glob.js
node ./bin/cli.js property-to-computed path/of/files/ or/some**/*glob.js
Input (alreadyHasDefaultImport.input.js):
import EmberObject from '@ember/object';
const Person = EmberObject.extend({
fullName: function() {
return `${this.firstName} ${this.lastName}`;
}.property('firstName', 'lastName'),
});
Output (alreadyHasDefaultImport.output.js):
import EmberObject, { computed } from '@ember/object';
const Person = EmberObject.extend({
fullName: computed('firstName', 'lastName', function() {
return `${this.firstName} ${this.lastName}`;
}),
});
Input (alreadyHasImport.input.js):
import { get } from '@ember/object';
const Person = EmberObject.extend({
fullName: function() {
return `${this.firstName} ${this.lastName}`;
}.property('firstName', 'lastName'),
});
Output (alreadyHasImport.output.js):
import { get, computed } from '@ember/object';
const Person = EmberObject.extend({
fullName: computed('firstName', 'lastName', function() {
return `${this.firstName} ${this.lastName}`;
}),
});
Input (basic.input.js):
import { computed } from '@ember/object';
const Person = EmberObject.extend({
fullName: function() {
return `${this.firstName} ${this.lastName}`;
}.property('firstName', 'lastName'),
});
Output (basic.output.js):
import { computed } from '@ember/object';
const Person = EmberObject.extend({
fullName: computed('firstName', 'lastName', function() {
return `${this.firstName} ${this.lastName}`;
}),
});
Input (import.input.js):
const Person = EmberObject.extend({
fullName: function() {
return `${this.firstName} ${this.lastName}`;
}.property('firstName', 'lastName'),
});
Output (import.output.js):
import { computed } from '@ember/object';
const Person = EmberObject.extend({
fullName: computed('firstName', 'lastName', function() {
return `${this.firstName} ${this.lastName}`;
}),
});