Just updated Ember to v1.13.5, and received this warning:
DEPRECATION: Controller#needs is deprecated, please use Ember.inject.controller() instead
Can't find the documentation yet on how to write the new syntax. Any suggestions on how to fix this warning would be appreciated.
Deprecation, in its programming sense, is the process of taking older code and marking it as no longer being useful within the codebase, usually because it has been superseded by newer code. The deprecated code is not immediately removed from the codebase because doing so may cause regression errors.
Using the @Deprecated Annotation To use it, you simply precede the class, method, or member declaration with "@Deprecated." Using the @Deprecated annotation to deprecate a class, method, or field ensures that all compilers will issue warnings when code uses that program element.
A deprecated API is one that you are no longer recommended to use, due to changes in the API. While deprecated classes, methods, and fields are still implemented, they may be removed in future implementations, so you should not use them in new code, and if possible rewrite old code not to use them.
The @Deprecated annotation tells the compiler that a method, class, or field is deprecated and that it should generate a warning if someone tries to use it. That's what a deprecated class or method is. It's no longer relevant.
For some reason it's marked as a private method in the docs, in order to see it you ll need to tick the private checkbox.
There are 2 ways to use it, with and without passing a controller name to it
App.PostController = Ember.Controller.extend({
posts: Ember.inject.controller()
});
When the name of the controller isn't passed, ember uses the property name to look it up such as posts: Ember.inject.controller('posts')
.
You will only ever specify the controller name when the property and the controller have different names.
App.PostController = Ember.Controller.extend({
myPosts: Ember.inject.controller('posts')
});
Here is one simple example and this blog post talks more about the evolution from manual injection to "Ember.inject"
export default Ember.Controller.extend({
flashManager: Ember.inject.controller('flash-message'),
actions: {
upVote: function() {
// Do some voting
var flashManager = this.get('flashManager');
flashManager.pushMessage('error', 'Your vote does not count');
}
}
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With