I\'ve written up an application that uses Ember Data. It\'s passing all it\'s tests and running as expected, however, something is causing a repeated deprecation warning to
Modifed for Ember 2.3 version (thank's to igorsantos07)
const alreadyShownFactory = () => {
let alreadyShown = [];
return (msg, test, opt) => {
if (test)
return false;
if( alreadyShown.indexOf(msg) === -1 ) {
let warning = 'DEPRECATION: ' + msg;
if(opt && opt.url) {
warning += ' See: ' + opt.url;
}
console.warn(warning);
alreadyShown.push(msg);
}
};
};
Ember.deprecate = alreadyShownFactory();
Ember.warn = alreadyShownFactory();
//see https://guides.emberjs.com/v2.3.0/configuring-ember/handling-deprecations/
Ember.Debug.registerDeprecationHandler((() => {
let alreadyShown = [];
return (message, options, next) => {
if(alreadyShown.indexOf(message) === -1) {
next(message, options);
alreadyShown.push(message);
}
};
})());
It's always good to consider deprecations, but if you want to just turn them off entirely add the following 2 lines to your main app.js file.
Ember.deprecate = function(){};
Ember.warn = function(i){};
You can just do Ember.deprecate = function(){}
in your application.js file and that should disable ember deprecation warnings.
For Ember 3.8 below code in app/initializers/deprecation.js worked for me. This disables the deprecations while running tests. You can modify according to your needs.
import { registerDeprecationHandler } from '@ember/debug';
import config from 'happyfox-web/config/environment';
export function initialize() {
registerDeprecationHandler((message, options, next) => {
if (config.environment === 'test') {
return;
} else {
next(message, options);
}
});
}
export default { initialize };
Took this from the docs
If you're looking for this in Ember >=2.0.0, you have to change this in:
Ember.Logger.warn = () => {}
Ember.Logger.deprecate = () => {}
My suggestion here, so you won't completely miss the deprecation warnings - they're there for a reason, right?
These are simplified versions of what deprecate
would do, but logging to DEBUG (so you can filter them out easily) and without the stacktrace (for simplicity). They'll also not show repeated messages:
CoffeeScript:
Ember.deprecate = (->
already_shown = []
(msg, test, opt)->
return false if test
if already_shown.indexOf(msg) == -1
warning = "DEPRECATION: #{msg}"
warning += " See: #{opt.url}" if opt.url
console.debug warning
already_shown.push msg
)()
JS:
Ember.deprecate = (function() {
var already_shown = [];
return function (msg, test, opt) {
if (test) return false;
if (already_shown.indexOf(msg) === -1) {
var warning = 'DEPRECATION: ' + msg;
if (opt.url) {
warning += ' See: ' + opt.url;
}
console.debug(warning);
}
already_shown.push(msg);
};
})();