Needed to move part of incomplete impl. to store

When using get with path (eg. get('foo.bar.baz')), get method is called
only on the current object and computed property will be called. Because
there is no easy way to overwrite the computed property, I moved
incomplete record loading to ember-data. It's not DRY and it should be
rewritten, but I don't want to do it at this point as we will need to
completely rewrite it when upgrading ember-data.
This commit is contained in:
Piotr Sarnacki 2012-10-30 23:48:49 +01:00
parent 74aa8ed503
commit 6bf5bd3356
3 changed files with 27 additions and 7 deletions

View File

@ -6,13 +6,6 @@
@loadedAttributes = []
@_super.apply this, arguments
get: (name) ->
if @constructor.isAttribute(name) && @get('incomplete') && !@isAttributeLoaded(name)
console.log 'Loading rest of', @constructor, @get('clientId'), 'for key: ', name
@loadTheRest()
@_super.apply this, arguments
refresh: ->
if id = @get('id')
store = @get('store')

View File

@ -89,6 +89,15 @@ describe 'Travis.Model', ->
runs ->
expect( record.get('complete') ).toBeFalsy()
it 'loads missing data if getPath is used', ->
other = Em.Object.create(record: record)
expect( other.get('record.description') ).toBeNull()
waits 50
runs ->
expect( other.get('record.description') ).toEqual 'bar'
expect( record.get('isComplete') ).toBeTruthy()
it 'loads missing data on try to get it', ->
expect( record.get('name') ).toEqual 'foo'
expect( record.get('description') ).toBeNull()

View File

@ -3255,6 +3255,12 @@ DS.attr = function(type, options) {
return Ember.computed(function(key, value) {
var data;
if(arguments.length === 1 && this.constructor.isAttribute(key) && get(this, 'incomplete') && !this.isAttributeLoaded(key)) {
if(this.loadTheRest) {
this.loadTheRest(key);
}
}
key = meta.key(this.constructor);
if (arguments.length === 2) {
@ -3389,6 +3395,12 @@ var hasAssociation = function(type, options, one) {
var data = get(this, 'data'), ids, id, association,
store = get(this, 'store');
if(arguments.length === 1 && this.constructor.isAttribute(key) && get(this, 'incomplete') && !this.isAttributeLoaded(key)) {
if(this.loadTheRest) {
this.loadTheRest(key);
}
}
if (typeof type === 'string') {
type = get(this, type, false) || get(window, type);
}
@ -3451,6 +3463,12 @@ var hasAssociation = function(type, options) {
store = get(this, 'store'),
ids, id, association;
if(arguments.length === 1 && this.constructor.isAttribute(key) && get(this, 'incomplete') && !this.isAttributeLoaded(key)) {
if(this.loadTheRest) {
this.loadTheRest(key);
}
}
if (typeof type === 'string') {
type = get(this, type, false) || get(window, type);
}