Skip to content

Commit bda3456

Browse files
committed
presist the Resource object between resource and method list view so that we don't have to requery it needlessly
1 parent a4654ef commit bda3456

File tree

2 files changed

+39
-15
lines changed

2 files changed

+39
-15
lines changed

js/views/methods/list.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ define([
1010
'views/forms/method',
1111
'views/methods/page',
1212
'collections/methods',
13-
'models/method',
13+
'models/resource',
1414
'models/notificationtotal'
15-
], function($, _, Backbone, Vm, Mustache, Session, resourceListTemplate, ResourceForm, MethodForm, MethodView, Methods, MethodModel, NTotals){
15+
], function($, _, Backbone, Vm, Mustache, Session, resourceListTemplate, ResourceForm, MethodForm, MethodView, Methods, ResourceModel, NTotals){
1616
var ApisPage = Backbone.View.extend({
1717
el: '.method-list-container',
1818
initialize: function () {
@@ -59,17 +59,23 @@ define([
5959
render: function () {
6060
var that = this;
6161
this.methods = new Methods();
62-
this.resource = new MethodModel();
62+
63+
// re-request resource only if necessary
64+
if (that.options.resource) {
65+
this.resource = that.options.resource;
66+
} else {
67+
this.resource = new ResourceModel();
68+
this.resource.options = {
69+
username: that.options.username,
70+
apiname: that.options.apiname,
71+
version: that.options.version,
72+
resourceId: that.options.resourceId
73+
};
74+
this.resource.fetch();
75+
}
6376
that.$el.attr('data-resource-id', that.options.resourceId);
6477
that.$el.fadeIn(200);
6578

66-
this.resource.set({
67-
username: that.options.username,
68-
apiname: that.options.apiname,
69-
version: that.options.version,
70-
resourceId: that.options.resourceId
71-
});
72-
this.resource.fetch();
7379
this.methods.username = that.options.username;
7480
this.methods.apiname = that.options.apiname;
7581
this.methods.version = that.options.version;

js/views/resource/list.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,19 @@ define([
4848
this.expandMethods(ele);
4949
},
5050
expandMethods: function (ele) {
51-
var resourceId = $(ele).attr('data-resource-id');
52-
var el = $(ele).next('li');
53-
var methodListView = Vm.create(this, 'methodlist'+this.options.resourceId, MethodsListView, {username: this.options.username, apiname: this.options.apiname, version: this.options.version, resourceId: resourceId, method: this.options.method, el: el});
51+
var resourceId = $(ele).attr('data-resource-id'),
52+
resource = this.resources.get(resourceId),
53+
el = $(ele).next('li');
54+
55+
var methodListView = Vm.create(this, 'methodlist'+this.options.resourceId, MethodsListView, {
56+
username: this.options.username,
57+
apiname: this.options.apiname,
58+
version: this.options.version,
59+
resourceId: resourceId,
60+
resource: resource,
61+
method: this.options.method,
62+
el: el
63+
});
5464
methodListView.setElement(el);
5565
methodListView.render();
5666
},
@@ -59,8 +69,11 @@ define([
5969
$('.resource-submenu').fadeOut(200);
6070
},
6171
render: function () {
62-
var that = this;
63-
var resources = new ResourcesCollection();
72+
var that = this,
73+
resources = new ResourcesCollection();
74+
75+
that.resources = resources; // assign to the view so we don't have to requery in method lists
76+
6477
resources.username = that.options.username;
6578
resources.apiname = that.options.apiname;
6679
resources.version = that.options.version;
@@ -110,6 +123,11 @@ define([
110123
});
111124

112125

126+
},
127+
128+
clean : function()
129+
{
130+
this.resources = null;
113131
}
114132
});
115133
return ApisPage;

0 commit comments

Comments
 (0)