Skip to content
This repository has been archived by the owner on Jan 5, 2023. It is now read-only.

Latest commit

 

History

History
114 lines (90 loc) · 2.38 KB

File metadata and controls

114 lines (90 loc) · 2.38 KB

getset-util

Usage

npx ember-getset-util-codemod getset-util path/of/files/ or/some**/*glob.js

# or

yarn global add ember-getset-util-codemod
ember-getset-util-codemod getset-util path/of/files/ or/some**/*glob.js

Input / Output


basic

Input (basic.input.js):

import Service from '@ember/service';

export default Service.extend({
  init() {
    this.set('hello', 'world');
    console.log(this.get('hello'));
  },

  doStuff() {
    this.getProperties(['hello']);
    this.setProperties({
      hello: 'world',
    });
  },
});

Output (basic.output.js):

import { get, getProperties, set, setProperties } from "@ember/object";
import Service from '@ember/service';

export default Service.extend({
  init() {
    set(this, 'hello', 'world');
    console.log(get(this, 'hello'));
  },

  doStuff() {
    getProperties(this, ['hello']);
    setProperties(this, {
      hello: 'world',
    });
  },
});

existing-imports

Input (existing-imports.input.js):

import { getWithDefault, get } from '@ember/object';
import Service from '@ember/service';

export default Service.extend({
  init() {
    get(this, 'hello');
    getWithDefault(this, 'hello', 'world');
    this.set('hello', 'world');
    console.log(this.get('hello'));
  },

  doStuff() {
    this.getProperties(['hello']);
    this.setProperties({
      hello: 'world',
    });
  },
});

Output (existing-imports.output.js):

import { getWithDefault, get, getProperties, set, setProperties } from '@ember/object';
import Service from '@ember/service';

export default Service.extend({
  init() {
    get(this, 'hello');
    getWithDefault(this, 'hello', 'world');
    set(this, 'hello', 'world');
    console.log(get(this, 'hello'));
  },

  doStuff() {
    getProperties(this, ['hello']);
    setProperties(this, {
      hello: 'world',
    });
  },
});