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
=== 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 15:14:21 +0000
@@ -470,7 +470,8 @@
470470
471 _removeRelationCallback: function(view,471 _removeRelationCallback: function(view,
472 relationElement, relationId, confirmButton, ev) {472 relationElement, relationId, confirmButton, ev) {
473 var db = this.get('component').get('db');473 var topo = this.get('component'),
474 db = topo.get('db');
474 var service = this.get('model');475 var service = this.get('model');
475 if (ev.err) {476 if (ev.err) {
476 db.notifications.add(477 db.notifications.add(
@@ -486,7 +487,7 @@
486 // Remove the relation from the DB.487 // Remove the relation from the DB.
487 db.relations.remove(db.relations.getById(relationId));488 db.relations.remove(db.relations.getById(relationId));
488 // Redraw the graph and reattach events.489 // Redraw the graph and reattach events.
489 db.fire('update');490 topo.update();
490 }491 }
491 view.get('rmrelation_dialog').hide();492 view.get('rmrelation_dialog').hide();
492 view.get('rmrelation_dialog').destroy();493 view.get('rmrelation_dialog').destroy();
@@ -688,28 +689,33 @@
688 },689 },
689690
690 /*691 /*
691 * Fired when clicking the second service is clicked in the692 *
693 * Fired when the second service is clicked in the
692 * add relation flow.694 * add relation flow.
693 *695 *
694 * :param endpoints: array of two endpoints, each in the form696 * @method addRelationEnd
697 * @param endpoints {Array} array of two endpoints, each in the form
695 * ['service name', {698 * ['service name', {
696 * name: 'endpoint type',699 * name: 'endpoint type',
697 * role: 'client or server'700 * role: 'client or server'
698 * }]701 * }].
702 * @param module {RelationModule}
703 * @return undefined Side-effects only.
699 */704 */
700 addRelationEnd: function(endpoints, view, context) {705 addRelationEnd: function(endpoints, module) {
701 // Redisplay all services706 // Redisplay all services
702 view.cancelRelationBuild();707 module.cancelRelationBuild();
703708
704 // Get the vis, and links, build the new relation.709 // Get the vis, and links, build the new relation.
705 var vis = view.get('component').vis;710 var topo = module.get('component');
706 var env = view.get('component').get('env');711 var vis = topo.vis;
707 var db = view.get('component').get('db');712 var env = topo.get('env');
708 var source = view.get('addRelationStart_service');713 var db = topo.get('db');
714 var source = module.get('addRelationStart_service');
709 var relation_id = 'pending-' + endpoints[0][0] + endpoints[1][0];715 var relation_id = 'pending-' + endpoints[0][0] + endpoints[1][0];
710716
711 if (endpoints[0][0] === endpoints[1][0]) {717 if (endpoints[0][0] === endpoints[1][0]) {
712 view.set('currentServiceClickAction', 'hideServiceMenu');718 module.set('currentServiceClickAction', 'hideServiceMenu');
713 return;719 return;
714 }720 }
715721
@@ -724,21 +730,20 @@
724730
725 // Firing the update event on the db will properly redraw the731 // Firing the update event on the db will properly redraw the
726 // graph and reattach events.732 // graph and reattach events.
727 //db.fire('update');733 topo.update();
728 view.get('component').bindAllD3Events();734 topo.bindAllD3Events();
729 view.update();
730735
731 // Fire event to add relation in juju.736 // Fire event to add relation in juju.
732 // This needs to specify interface in the future.737 // This needs to specify interface in the future.
733 env.add_relation(endpoints[0], endpoints[1],738 env.add_relation(endpoints[0], endpoints[1],
734 Y.bind(this._addRelationCallback, this, view, relation_id)739 Y.bind(this._addRelationCallback, this, module, relation_id)
735 );740 );
736 view.set('currentServiceClickAction', 'hideServiceMenu');741 module.set('currentServiceClickAction', 'hideServiceMenu');
737 },742 },
738743
739 _addRelationCallback: function(view, relation_id, ev) {744 _addRelationCallback: function(module, relation_id, ev) {
740 console.log('addRelationCallback reached');745 console.log('addRelationCallback reached');
741 var topo = view.get('component');746 var topo = module.get('component');
742 var db = topo.get('db');747 var db = topo.get('db');
743 var vis = topo.vis;748 var vis = topo.vis;
744 // Remove our pending relation from the DB, error or no.749 // Remove our pending relation from the DB, error or no.
@@ -772,10 +777,8 @@
772 display_name: endpoints[0][1].name777 display_name: endpoints[0][1].name
773 });778 });
774 }779 }
775 // Redraw the graph and reattach events.780 topo.update();
776 //db.fire('update');781 topo.bindAllD3Events();
777 view.get('component').bindAllD3Events();
778 view.update();
779 },782 },
780783
781 /*784 /*
782785
=== modified file 'app/views/topology/service.js'
--- app/views/topology/service.js 2013-03-27 18:01:33 +0000
+++ app/views/topology/service.js 2013-03-28 15:14:21 +0000
@@ -1060,7 +1060,8 @@
10601060
1061 _destroyCallback: function(service, btn, ev) {1061 _destroyCallback: function(service, btn, ev) {
1062 var getModelURL = this.get('component').get('getModelURL'),1062 var getModelURL = this.get('component').get('getModelURL'),
1063 db = this.get('component').get('db');1063 topo = this.get('component'),
1064 db = topo.get('db');
1064 if (ev.err) {1065 if (ev.err) {
1065 db.notifications.add(1066 db.notifications.add(
1066 new models.Notification({1067 new models.Notification({
@@ -1076,7 +1077,7 @@
1076 relation.destroy();1077 relation.destroy();
1077 });1078 });
1078 service.destroy();1079 service.destroy();
1079 db.fire('update');1080 topo.update();
1080 }1081 }
1081 this.get('destroy_dialog').hide();1082 this.get('destroy_dialog').hide();
1082 btn.set('disabled', false);1083 btn.set('disabled', false);

Subscribers

People subscribed via source and target branches