public
Last active

Debugging Ember

  • Download Gist
debuggingEmber.md
Markdown

Debugging EmberJS and EmberData:

  • Log router transitions:

    window.App = Ember.Application.create({
      LOG_TRANSITIONS: true,
    });
    
  • Log object bindings:

    Ember.LOG_BINDINGS = true
    
  • View all registered routes

    Ember.keys(App.Router.router.recognizer.names)
    
  • View all registered templates

    Ember.keys(Ember.TEMPLATES)
    
  • View the state history of an ember-data record:

    record.stateManager.get('currentPath')
    
  • View an instance of something from the container

    App.__container__.lookup("controller:posts")
    App.__container__.lookup("route:application")
    
  • View ember-data's identity map:

    App.__container__.lookup('store:main').recordCache # all records in memory
    App.__container__.lookup('store:main').recordCache[2].get('data.attributes') #attributes
    App.__container__.lookup('store:main').recordCache[2].get('comments') #loaded associations
    
  • See all observers for a object, key:

      Ember.observersFor(comments, keyName);
    
  • Dealing with deprecations:

    Ember.ENV.RAISE_ON_DEPRECATION = true
    Ember.LOG_STACKTRACE_ON_DEPRECATION = true
    
  • Handlebars

    {{debugger}}
    {{log record}}
    
  • Implement a Ember.onerror hook to log all errors in production:

     Ember.onerror = function(error) {
       Em.$.ajax('/error-notification', 'POST', {
         stack: error.stack,
         otherInformation: 'exception message'
       });
     };
    
  • Use ember extension when its ready.

    https://github.com/tildeio/ember-extension.git
    

I definitely enjoy using record.set("stateManager.enableLogging", true), it helps a lot when debugging states and what is really happening with the record behind the scenes.

You can also inspect DOM elements for view ids, for example something like ember432 and then lookup the view object via Ember.View.views["ember432"]

@darthdeus - Thanks added.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.