Skip to content

Latest commit

 

History

History
133 lines (109 loc) · 3.65 KB

File metadata and controls

133 lines (109 loc) · 3.65 KB

property-to-computed

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.

Usage

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

Local Usage

node ./bin/cli.js property-to-computed path/of/files/ or/some**/*glob.js

Input / Output


alreadyHasDefaultImport

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}`;
  }),
});

alreadyHasImport

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}`;
  }),
});

basic

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}`;
  }),
});

import

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}`;
  }),
});