fivetanley / ember-cli-migrator

migrate your files to the standard ember-cli structure, preserving git history
MIT License
106 stars 22 forks source link

handling Global calls within an object #49

Open koryteg opened 9 years ago

koryteg commented 9 years ago

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")
});
fivetanley commented 9 years ago

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.

koryteg commented 9 years ago

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.