Merge lp:~bcsaller/juju-gui/update-reductions into lp:juju-gui/experimental

Proposed by Benjamin Saller
Status: Merged
Merged at revision: 467
Proposed branch: lp:~bcsaller/juju-gui/update-reductions
Merge into: lp:juju-gui/experimental
Diff against target: 130 lines (+29/-25)
2 files modified
app/views/topology/relation.js (+26/-23)
app/views/topology/service.js (+3/-2)
To merge this branch: bzr merge lp:~bcsaller/juju-gui/update-reductions
Reviewer Review Type Date Requested Status
Juju GUI Hackers Pending
Review via email: mp+155972@code.launchpad.net

Description of the change

Remove some db.update calls

Given the current model we can't remove all calls
to db.fire('update') but we can remove them from
anything using the topology. Change 'update' events
(which redispatch) so simply call topo.update().

service and charm views still redispatch.

https://codereview.appspot.com/8083043/

To post a comment you must log in.
Revision history for this message
Benjamin Saller (bcsaller) wrote :
Download full text (5.0 KiB)

Reviewers: mp+155972_code.launchpad.net,

Message:
Please take a look.

Description:
Remove some db.update calls

Given the current model we can't remove all calls
to db.fire('update') but we can remove them from
anything using the topology. Change 'update' events
(which redispatch) so simply call topo.update().

service and charm views still redispatch.

https://code.launchpad.net/~bcsaller/juju-gui/update-reductions/+merge/155972

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/8083043/

Affected files:
   A [revision details]
   M app/views/topology/relation.js
   M app/views/topology/service.js

Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: <email address hidden>
+New revision: <email address hidden>

Index: app/views/topology/relation.js
=== modified file 'app/views/topology/relation.js'
--- app/views/topology/relation.js 2013-03-22 10:28:31 +0000
+++ app/views/topology/relation.js 2013-03-28 14:22:42 +0000
@@ -470,7 +470,8 @@

      _removeRelationCallback: function(view,
              relationElement, relationId, confirmButton, ev) {
- var db = this.get('component').get('db');
+ var topo = this.get('component'),
+ db = topo.get('db');
        var service = this.get('model');
        if (ev.err) {
          db.notifications.add(
@@ -486,7 +487,7 @@
          // Remove the relation from the DB.
          db.relations.remove(db.relations.getById(relationId));
          // Redraw the graph and reattach events.
- db.fire('update');
+ topo.update();
        }
        view.get('rmrelation_dialog').hide();
        view.get('rmrelation_dialog').destroy();
@@ -697,19 +698,20 @@
       * role: 'client or server'
       * }]
       */
- addRelationEnd: function(endpoints, view, context) {
+ addRelationEnd: function(endpoints, module) {
        // Redisplay all services
- view.cancelRelationBuild();
+ module.cancelRelationBuild();

        // Get the vis, and links, build the new relation.
- var vis = view.get('component').vis;
- var env = view.get('component').get('env');
- var db = view.get('component').get('db');
- var source = view.get('addRelationStart_service');
+ var topo = module.get('component');
+ var vis = topo.vis;
+ var env = topo.get('env');
+ var db = topo.get('db');
+ var source = module.get('addRelationStart_service');
        var relation_id = 'pending-' + endpoints[0][0] + endpoints[1][0];

        if (endpoints[0][0] === endpoints[1][0]) {
- view.set('currentServiceClickAction', 'hideServiceMenu');
+ module.set('currentServiceClickAction', 'hideServiceMenu');
          return;
        }

@@ -724,21 +726,20 @@

        // Firing the update event on the db will properly redraw the
        // graph and reattach events.
- //db.fire('update');
- view.get('component').bindAllD3Events();
- view.update();
+ topo.update();
+ topo.bindAllD3Events();
...

Read more...

Revision history for this message
Jeff Pihach (hatch) wrote :

Thanks for this cleanup LGTM with trivial

https://codereview.appspot.com/8083043/diff/1/app/views/topology/relation.js
File app/views/topology/relation.js (right):

https://codereview.appspot.com/8083043/diff/1/app/views/topology/relation.js#newcode701
app/views/topology/relation.js:701: addRelationEnd: function(endpoints,
module) {
Could you document this method please :)

https://codereview.appspot.com/8083043/

467. By Benjamin Saller

expanded doc as requested in review

Revision history for this message
Benjamin Saller (bcsaller) wrote :

Thanks for review.

https://codereview.appspot.com/8083043/diff/1/app/views/topology/relation.js
File app/views/topology/relation.js (right):

https://codereview.appspot.com/8083043/diff/1/app/views/topology/relation.js#newcode701
app/views/topology/relation.js:701: addRelationEnd: function(endpoints,
module) {
On 2013/03/28 14:50:33, jeff.pihach wrote:
> Could you document this method please :)

Updated doc to yuidoc. Pushed but not reproposed.

https://codereview.appspot.com/8083043/

Revision history for this message
Gary Poster (gary) wrote :

LGTM. nice cleanup. Thank you.

Gary

https://codereview.appspot.com/8083043/

Revision history for this message
Benjamin Saller (bcsaller) wrote :

*** Submitted:

Remove some db.update calls

Given the current model we can't remove all calls
to db.fire('update') but we can remove them from
anything using the topology. Change 'update' events
(which redispatch) so simply call topo.update().

service and charm views still redispatch.

R=jeff.pihach, gary.poster
CC=
https://codereview.appspot.com/8083043

https://codereview.appspot.com/8083043/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'app/views/topology/relation.js'
2--- app/views/topology/relation.js 2013-03-22 10:28:31 +0000
3+++ app/views/topology/relation.js 2013-03-28 15:14:21 +0000
4@@ -470,7 +470,8 @@
5
6 _removeRelationCallback: function(view,
7 relationElement, relationId, confirmButton, ev) {
8- var db = this.get('component').get('db');
9+ var topo = this.get('component'),
10+ db = topo.get('db');
11 var service = this.get('model');
12 if (ev.err) {
13 db.notifications.add(
14@@ -486,7 +487,7 @@
15 // Remove the relation from the DB.
16 db.relations.remove(db.relations.getById(relationId));
17 // Redraw the graph and reattach events.
18- db.fire('update');
19+ topo.update();
20 }
21 view.get('rmrelation_dialog').hide();
22 view.get('rmrelation_dialog').destroy();
23@@ -688,28 +689,33 @@
24 },
25
26 /*
27- * Fired when clicking the second service is clicked in the
28+ *
29+ * Fired when the second service is clicked in the
30 * add relation flow.
31 *
32- * :param endpoints: array of two endpoints, each in the form
33+ * @method addRelationEnd
34+ * @param endpoints {Array} array of two endpoints, each in the form
35 * ['service name', {
36 * name: 'endpoint type',
37 * role: 'client or server'
38- * }]
39+ * }].
40+ * @param module {RelationModule}
41+ * @return undefined Side-effects only.
42 */
43- addRelationEnd: function(endpoints, view, context) {
44+ addRelationEnd: function(endpoints, module) {
45 // Redisplay all services
46- view.cancelRelationBuild();
47+ module.cancelRelationBuild();
48
49 // Get the vis, and links, build the new relation.
50- var vis = view.get('component').vis;
51- var env = view.get('component').get('env');
52- var db = view.get('component').get('db');
53- var source = view.get('addRelationStart_service');
54+ var topo = module.get('component');
55+ var vis = topo.vis;
56+ var env = topo.get('env');
57+ var db = topo.get('db');
58+ var source = module.get('addRelationStart_service');
59 var relation_id = 'pending-' + endpoints[0][0] + endpoints[1][0];
60
61 if (endpoints[0][0] === endpoints[1][0]) {
62- view.set('currentServiceClickAction', 'hideServiceMenu');
63+ module.set('currentServiceClickAction', 'hideServiceMenu');
64 return;
65 }
66
67@@ -724,21 +730,20 @@
68
69 // Firing the update event on the db will properly redraw the
70 // graph and reattach events.
71- //db.fire('update');
72- view.get('component').bindAllD3Events();
73- view.update();
74+ topo.update();
75+ topo.bindAllD3Events();
76
77 // Fire event to add relation in juju.
78 // This needs to specify interface in the future.
79 env.add_relation(endpoints[0], endpoints[1],
80- Y.bind(this._addRelationCallback, this, view, relation_id)
81+ Y.bind(this._addRelationCallback, this, module, relation_id)
82 );
83- view.set('currentServiceClickAction', 'hideServiceMenu');
84+ module.set('currentServiceClickAction', 'hideServiceMenu');
85 },
86
87- _addRelationCallback: function(view, relation_id, ev) {
88+ _addRelationCallback: function(module, relation_id, ev) {
89 console.log('addRelationCallback reached');
90- var topo = view.get('component');
91+ var topo = module.get('component');
92 var db = topo.get('db');
93 var vis = topo.vis;
94 // Remove our pending relation from the DB, error or no.
95@@ -772,10 +777,8 @@
96 display_name: endpoints[0][1].name
97 });
98 }
99- // Redraw the graph and reattach events.
100- //db.fire('update');
101- view.get('component').bindAllD3Events();
102- view.update();
103+ topo.update();
104+ topo.bindAllD3Events();
105 },
106
107 /*
108
109=== modified file 'app/views/topology/service.js'
110--- app/views/topology/service.js 2013-03-27 18:01:33 +0000
111+++ app/views/topology/service.js 2013-03-28 15:14:21 +0000
112@@ -1060,7 +1060,8 @@
113
114 _destroyCallback: function(service, btn, ev) {
115 var getModelURL = this.get('component').get('getModelURL'),
116- db = this.get('component').get('db');
117+ topo = this.get('component'),
118+ db = topo.get('db');
119 if (ev.err) {
120 db.notifications.add(
121 new models.Notification({
122@@ -1076,7 +1077,7 @@
123 relation.destroy();
124 });
125 service.destroy();
126- db.fire('update');
127+ topo.update();
128 }
129 this.get('destroy_dialog').hide();
130 btn.set('disabled', false);

Subscribers

People subscribed via source and target branches