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:
parent
74aa8ed503
commit
6bf5bd3356
|
@ -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')
|
||||
|
|
|
@ -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()
|
||||
|
|
18
assets/scripts/vendor/ember-data.js
vendored
18
assets/scripts/vendor/ember-data.js
vendored
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user