Skip to content
This repository has been archived by the owner on Dec 1, 2017. It is now read-only.

Commit

Permalink
Merge pull request #68 from karthikv/element-retrieval
Browse files Browse the repository at this point in the history
Pipe element retrieval deferreds so as to circumvent CanJS bug with simultaneous fetching.
  • Loading branch information
Jennifer Fong committed Aug 30, 2012
2 parents 30c0fb2 + 746a4be commit a439ea2
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion public/javascripts/controllers/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ define(['can', './extended', './element', 'models/element', 'helpers/screen-util
'helpers/errors', 'can.super', 'jquery.ui'],
function(can, ExtendedControl, ElementControl, ElementModel, screenUtils, errors) {
return ExtendedControl({
fetchingElements: null
}, {
init: function($element, options) {
this._super($element, options);
this.component = options.component;
Expand Down Expand Up @@ -37,9 +39,20 @@ define(['can', './extended', './element', 'models/element', 'helpers/screen-util
if (self.cachedElements) {
self.traverseElementLinkedList();
} else {
if (this.constructor.fetchingElements) {
// pipe all element retrieval into one deferred to prevent
// simultaneous fetching, as this causes a bug in CanJS
this.constructor.fetchingElements = this.constructor
.fetchingElements.pipe(getElements);
} else {
this.constructor.fetchingElements = getElements();
}
}

function getElements() {
// TODO: optimize this when layout row is removed (new request for
// every moved component)
ElementModel.withRouteData()
return ElementModel.withRouteData()
.findAll({ componentId: componentId })
.then(function(elements) {
self.cachedElements = elements;
Expand Down

0 comments on commit a439ea2

Please sign in to comment.