3
votes

Somewhere in my code, I hit a bug. I put a breakpoint to try and see what is happening. When I inspect the object "foo" in the console I get:

foo.toString() > "<App.Foo:ember661:174009>" // all good
foo.get('isLoaded') > true 
foo.get('isValid') > true 

Yet:

foo.get('name') > null // Whereas it definitely has a name.

When I look at the Network tab in the developer tools, I can see that it is still "finishing" to load the record. For the corresponding URL, it says: "pending".

What is this model state? How do you know when a model is "fully" ready?

UPDATE: per my comment to Mike, I should have added that I am inspecting this record within a registerBoundHelper function. So I guess there is a context issue that I am missing. Indeed:

... foo template ...
{{ name }} // properly set to a value
{{ my_helper this }}

... helpers ...
Ember.Handlebars.registerBoundHelper('my_helper', function(foo) {
    return foo.get('name'); // name property is null!!
}); 

I must be missing something obvious?

Thanks, PJ

2
Are you loading from JSON? If so, are you sure it's valid? - Neikos

2 Answers

1
votes

What is this model state?

Can't tell given the info you provided, but to find out from console you could try this:

foo.stateManager.get('currentPath') > should be something like "rootState.loaded.saved"

Then have a look at states.js source code for details on that state.

How do you know when a model is "fully" ready?

Depends what you mean by fully and ready. Some tricks to help you see what's what:

Show me the raw data for a model

foo.get('data')
foo.get('data.attributes')

Get console log output when the record transitions between states

record.set("stateManager.enableLogging", true)
0
votes

Answering my own question, in case it helps someone else...

This strange behaviour came from a context issue for the helper. It was pretty "deep" in a view (several nested levels down) and I am using a combination of {{partial}} and the new {{render}} that you can now use multiple times (on master). I'd lie if I were to say I am totally clear with what was happening, but I tried various contexts switches and it ended up working.

So I guess if you hit something like that, double check your helpers's context...