From 6bf5bd33568473e07cf5337331830af8bfffab0d Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Tue, 30 Oct 2012 23:48:49 +0100 Subject: [PATCH] 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. --- assets/scripts/lib/travis/model.coffee | 7 ------- .../scripts/spec/unit/incomplete_spec.coffee | 9 +++++++++ assets/scripts/vendor/ember-data.js | 18 ++++++++++++++++++ 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/assets/scripts/lib/travis/model.coffee b/assets/scripts/lib/travis/model.coffee index 099e515b..fa5722e2 100644 --- a/assets/scripts/lib/travis/model.coffee +++ b/assets/scripts/lib/travis/model.coffee @@ -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') diff --git a/assets/scripts/spec/unit/incomplete_spec.coffee b/assets/scripts/spec/unit/incomplete_spec.coffee index 4ac494e9..676752c3 100644 --- a/assets/scripts/spec/unit/incomplete_spec.coffee +++ b/assets/scripts/spec/unit/incomplete_spec.coffee @@ -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() diff --git a/assets/scripts/vendor/ember-data.js b/assets/scripts/vendor/ember-data.js index e86afd5d..8e09d046 100644 --- a/assets/scripts/vendor/ember-data.js +++ b/assets/scripts/vendor/ember-data.js @@ -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); }