How to disable deprecation warnings in Ember.js?

前端 未结 6 1307
心在旅途
心在旅途 2021-01-08 01:09

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

相关标签:
6条回答
  • 2021-01-08 01:51

    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);
        }
      };
    })());
    
    0 讨论(0)
  • 2021-01-08 01:54

    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){};
    
    0 讨论(0)
  • 2021-01-08 02:02

    You can just do Ember.deprecate = function(){} in your application.js file and that should disable ember deprecation warnings.

    0 讨论(0)
  • 2021-01-08 02:02

    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

    0 讨论(0)
  • 2021-01-08 02:02

    If you're looking for this in Ember >=2.0.0, you have to change this in:

    Ember.Logger.warn = () => {}
    Ember.Logger.deprecate = () => {}
    
    0 讨论(0)
  • 2021-01-08 02:10

    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);
      };
    })();
    
    0 讨论(0)
提交回复
热议问题