ember-cli-migrator icon indicating copy to clipboard operation
ember-cli-migrator copied to clipboard

handling Global calls within an object

Open koryteg opened this issue 9 years ago • 2 comments

looks like as of right now the migrator just parses the JS for any declaration of the global namespace declared and removes it.

if it could change the global declaration to its correct instance call. ie:

MyApp.ApplicationController = Ember.ObjectController.extend({
  updateCurrentPath: (function() {
    MyApp.set("currentPath", this.get("currentPath"));
  }).observes("currentPath")
});

should get changed to :

ApplicationController = Ember.ObjectController.extend({
  updateCurrentPath: (function() {
    this.container.lookup('application:main').set("currentPath", this.get("currentPath"));
  }).observes("currentPath")
});

koryteg avatar Mar 08 '15 02:03 koryteg

I think the path moving forward for this is moving stuff to the application controller and using needs... might be possible to do automatically too. Just cuz container is private api and likely to break, would be great to not encourage people to use private api.

fivetanley avatar Mar 15 '15 19:03 fivetanley

right that sounds like the correct approach, I am still learning some of the best practices of ember. looks like the new service objects feature might be a good option as well.

an easy quick short term solution might be to add a step in the usage docs to remind people that everywhere they are using globals inside a class will need to be refactored.

koryteg avatar Mar 16 '15 16:03 koryteg