I have the following Ember model for users, which contains a list of permissions:
App.User = DS.Model.extend({
username: DS.attr(),
permissions: DS.attr(), //e.g. ['edit', 'read']
isEditor: function() {
var perms = this.get('permissions');
return perms.indexOf('edit') > -1;
}.property('permissions')
});
I use this, amongst other things, to get a list of editors in a controller (for use in a select
). When I load the page, I get this error in the console:
Error: Something you did caused a view to re-render after it rendered but before it was inserted into the DOM.
It happened after adding the isEditor
function, and if I comment out the contents of the function it works fine, although obviously the list I'm generating from it is incorrect. But as far as I can see there is nothing wrong with the code.
Edit: I'm using the function in a controller mixin:
App.EditorsMixin = Ember.Mixin.create({
editors: function() {
return this.store.filter('user', function(model) {
return model.get('isEditor');
});
}.property()
});
Edit 2: It seems that the problem might be related to the fact that not all store.find('user')
promises are fulfilled when editors
is called. Adding in a few console.log
lines and running it though the debugger, I can see that I need something like this:
editors: function() {
this.store.find('user').then(function() {
return this.store.filter('user', function(model) {
return model.get('isEditor');
});
});
}.property()
But I can't figure out how to get a list of editors out of the mess of nested promises.
TypeError: perms is undefined
before the other error though. Is there a sensible way to debug this sort of issue? All I can think of is comment out blocks until I find something that makes a difference but that's not really ideal. – aquavitae