项目作者: craigbilner

项目描述 :
Replaces promise chains with anonymous functions with named versions
高级语言: JavaScript
项目地址: git://github.com/craigbilner/ember-name-promise-codemod.git
创建时间: 2017-02-03T15:30:22Z
项目社区:https://github.com/craigbilner/ember-name-promise-codemod

开源协议:Apache License 2.0

下载


Ember name promise codemod

To conform to this linting rule,
this codemod replaces promise chains with anonymous functions with named versions.

Changes

willChange

  1. import Ember from 'ember';
  2. export default Ember.Component.extend({
  3. actions: {
  4. updateUser(user) {
  5. user.save().then((a) => {
  6. return user.reload();
  7. }).then(() => {
  8. this.notifyAboutSuccess();
  9. }).then((c) => 5);
  10. },
  11. },
  12. });

will become

  1. import Ember from 'ember';
  2. export default Ember.Component.extend({
  3. _p3(a) {
  4. return user.reload();
  5. },
  6. _p2() {
  7. this.notifyAboutSuccess();
  8. },
  9. _p1(c) {
  10. return 5;
  11. },
  12. actions: {
  13. updateUser(user) {
  14. user.save().then(this._p3.bind(this)).then(this._p2.bind(this)).then(this._p1.bind(this));
  15. },
  16. },
  17. });

wontChange

non-anonymous functions

  1. import Ember from 'ember';
  2. import foo from 'somewhere';
  3. import bar from 'somewhereElse';
  4. export default Ember.Component.extend({
  5. _p1() {
  6. return user.reload();
  7. },
  8. _p2() {
  9. this.notifyAboutSuccess();
  10. },
  11. _p3() {
  12. return 5;
  13. },
  14. actions: {
  15. updateUser(user) {
  16. user.save()
  17. .then(this._p1.bind(this))
  18. .then(this._p2.bind(this))
  19. .then(foo)
  20. .then(bar.baz);
  21. },
  22. },
  23. });