Deprecating ObjectController


(Robin Ward) #1

Ember 1.11 includes a major deprecation that affects Discourse in a big way: ObjectController has been deprecated. We unfortunately have dozens of ObjectControllers in our codebase and they will need to be migrated to regular Controllers.

It would take too long migrate them all in this release, so the plan is to have developers can fix them incrementally they encounter them. Here is my suggested plan of attack:

  • Leave all controllers as ObjectControllers for now. I have actually silenced their warnings so in development mode for now you will not even be alerted to it.

  • You will get warnings when the deprecated functionality of an ObjectController is used. Here’s how to fix them:

    • In a template, {{name}} will output a deprecation in the console until you replace it with

    • In the ObjectController, any calls to this.get('name') will have to be replaced with this.get('')

    • Sometimes we’d add additional properties to the ObjectController itself without declaring them. If you call this.set and expect the value to be set on the controller itself, make sure you initialize the property like this: customProperty: null when the ObjectController is declared.

    • This goes without saying but test the functionality of properties you changed. Make sure the site still works in your browser. Do not submit PRs you haven’t tested thoroughly.

Over time, we will reduce the amount of proxy errors to nothing. Once we do this, we will convert all ObjectController instances to Controller and identify any more regressions.

Ember 1.11 Upgrade Notes + Discourse Stability
Local customizations broke site on upgrade, how to disable?
Local customizations broke site on upgrade, how to disable?
(Sam Saffron) #2

For the record, I love this change. This magic always bothered me.

(Marty Penner) #3

Is there any value in someone (like myself) systematically going through all affected controllers / templates and converting the syntax, independent of being attached to another bugfix or feature? If so, should pull requests be sent in small-ish chunks, or one big enchilada at the end?

(Mittineague) #4

I’ve been seeing Deprecated warnings during my development of plugins.
I assumed you would be aware of them from running unit tests, but if not I can report them as I see them.

(Erick Guan) #5

It’s hard and will be problematic. It’s OK to update them when you fix a bug or submit a feature(if you see the deprecation warning).
Actually, most of them have already been updated.

(Marty Penner) #6

@fantasticfears Ah, OK. Thanks for the update.

(Erick Guan) #7

Another deprecating feature related to incoming Ember 2.1:

itemController and itemXXX in #each block is going to replaced by components. It’s also the chance to wrap them into a component :smile:

(Jeff Atwood) #8

We only need to worry about one step at a time…