Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Console logging on ember js

I would just like to ask why is it that when you print out on the console on ember it gives you a string? but if you typeof on it, it gives you a function?

ex. sample = Ember.Route.extend();

console.log(sample); // prints (subclass of Ember.Route)

console.log(typeof sample); // function

Can someone explain this please? Aside with their documentation that is hard to grasp. It's really hard to debug on ember, even with ember inspector. Is there any tool or way to properly debug ember.

like image 268
olanchuy Avatar asked Oct 16 '14 19:10

olanchuy


People also ask

What is logging to the console?

console. log specifically is a method for developers to write code to inconspicuously inform the developers what the code is doing. It can be used to alert you that there's an issue, but shouldn't take the place of an interactive debugger when it comes time to debug the code.

Is Ember JS frontend or backend?

AngularJS and Ember. js are designed to be backend agnostic. It's a good rule to keep the back-end independent since the front-end is seeing a lot more growth. This decision will save you some trouble in the future when you want to modify your front-end a year or two down the line.

Is Ember a backend?

The most important thing to know is that Ember. js is completely backend-agnostic. You could write this part just as well in Ruby, PHP, Python or any other server language.


1 Answers

In terms of Ember debugging, you probably already read this: https://guides.emberjs.com/release/configuring-ember/debugging/

There is a couple of great feature, what you can turn on during development, to get more information, what's happening under the hood.

You can insert in your app.js:

var App = Ember.Application.extend({
  LOG_TRANSITIONS_INTERNAL:  true,
  LOG_ACTIVE_GENERATION:     true,
  LOG_VIEW_LOOKUPS:          true,
  LOG_RESOLVER:              true,
});

Ember.run.backburner.DEBUG            = true;
Ember.ENV.RAISE_ON_DEPRECATION        = true;
Ember.LOG_STACKTRACE_ON_DEPRECATION   = true;
Ember.LOG_BINDINGS                    = true;
Ember.RSVP.on('error', function(error) {
  Ember.Logger.assert(false, error);
});

You can stop your code if you write debugger in your code. I use it quite often to figure out what's happening there.

In terms of your question, if you extend an Ember class it basically create a new function, but behave as a subclass of extended class. You can check what's happening there: https://github.com/emberjs/ember.js/blob/v1.7.0/packages/ember-runtime/lib/system/core_object.js#L536-L556

When you run your Ember app, your app gonna be wrapped in a container, so if you need access to properties or variables, you have to use this - assume your app name is 'App':

App.__container__.lookup("controller:application").get("currentRouteName")
App.__container__.lookup("controller:application").get("currentPath")
App.__container__.lookup("controller:application").get("model")

It is take a while to understand how could you debug your ember app, but worth to learn and invest more time in it, because will be quite handy later.

If you have any question, don't hesitate to comment and we can solve it.

About debugger;

It is like a breakpoint, you can stop the code. "Inspect element"/"Developer Tool" have to be open in Chrome. Little example here: http://jsbin.com/cugetoxoyira/45

Source code: http://jsbin.com/cugetoxoyira/45/edit In Line 18, there is a debugger; , so you can check in your console what is in controller or in model params. You have to type in only controller in your Console in Developer Tool of Chrome.

like image 151
Zoltan Avatar answered Oct 08 '22 13:10

Zoltan