Skip to content

Commit fe7e738

Browse files
committed
Better comments.
1 parent 77ba8a2 commit fe7e738

3 files changed

Lines changed: 34 additions & 26 deletions

File tree

apps/src/netsim/NetSimVizSimulationNode.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ var NetSimVizSimulationNode = module.exports = function (sourceNode,
3333
NetSimVizNode.call(this, useBackgroundAnimation);
3434

3535
/**
36-
* ID of the simulation node that this viz element represents.
36+
* ID of the NetSimNode that this NetSimVizSimulationNode represents.
3737
* @type {number}
3838
*/
3939
this.correspondingNodeID_ = sourceNode.entityID;
4040

4141
/**
42-
* UUID of the simulation node that this viz element represents.
42+
* UUID of the NetSimNode that this NetSimVizSimulationNode represents.
4343
* @type {string}
4444
*/
4545
this.correspondingNodeUuid_ = sourceNode.uuid;

apps/src/netsim/NetSimVizSimulationWire.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ var NetSimVizSimulationWire = module.exports = function (sourceWire,
3232
NetSimVizWire.call(this, localNode, remoteNode);
3333

3434
/**
35-
* ID of the simulation wire that this viz element maps to.
35+
* ID of the NetSimWire that this NetSimVizSimulationWire maps to.
3636
* @type {number}
3737
*/
3838
this.correspondingWireId_ = sourceWire.entityID;
3939

4040
/**
41-
* UUID of the simulation wire that this viz element maps to.
41+
* UUID of the NetSimWire that this NetSimVizSimulationWire maps to.
4242
* @type {number}
4343
*/
4444
this.correspondingWireUuid_ = sourceWire.uuid;
@@ -81,7 +81,7 @@ NetSimVizSimulationWire.prototype.configureFrom = function (sourceWire) {
8181
};
8282

8383
/**
84-
* ID of the simulation entity that maps to this one.
84+
* ID of the NetSimEntity that maps to this visualization element.
8585
* @returns {number}
8686
*/
8787
NetSimVizSimulationWire.prototype.getCorrespondingEntityId = function () {
@@ -90,7 +90,7 @@ NetSimVizSimulationWire.prototype.getCorrespondingEntityId = function () {
9090

9191
/**
9292
* @param {NetSimEntity} entity
93-
* @returns {boolean} TRUE of this VizElement represents the given Entity.
93+
* @returns {boolean} TRUE if this VizElement represents the given NetSimEntity.
9494
*/
9595
NetSimVizSimulationWire.prototype.representsEntity = function (entity) {
9696
return this.correspondingWireId_ === entity.entityID &&
@@ -99,7 +99,7 @@ NetSimVizSimulationWire.prototype.representsEntity = function (entity) {
9999

100100
/**
101101
* Killing a visualization node removes its ID so that it won't conflict with
102-
* another node of matching ID being added, and begins its exit animation.
102+
* another viznode of matching ID being added, and begins its exit animation.
103103
* @override
104104
*/
105105
NetSimVizSimulationWire.prototype.kill = function () {

apps/test/netsim/NetSimVisualization.js

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -110,47 +110,55 @@ describe("NetSimVisualization", function () {
110110

111111
// Connect to shard
112112
testShard = fakeShard();
113-
var myNode = createNode(testShard, 'myNode');
113+
var oldNode1 = createNode(testShard, 'myNode');
114114
netSimVis.setShard(testShard);
115-
netSimVis.setLocalNode(myNode);
115+
netSimVis.setLocalNode(oldNode1);
116116

117-
// Make a couple more nodes, and make sure the visualization picks them up.
118-
var node2 = createNode(testShard, 'node2');
119-
var node3 = createNode(testShard, 'node3');
117+
// Make a couple more nodes. Now that we've called `setShard` the
118+
// visualization should automatically detect these nodes and create
119+
// corresponding VizElements in its elements_ collection.
120+
var oldNode2 = createNode(testShard, 'node2');
121+
var oldNode3 = createNode(testShard, 'node3');
120122

121-
// Check out the list of viz elements
123+
// Make sure the visualization now includes all three nodes.
122124
assert.equal(3, netSimVis.elements_.length);
123125

124126
// Introduce a new shard, with new data
125127
var testShard2 = fakeShard();
126-
var newNode = createNode(testShard2, 'newNode');
128+
var newNode1 = createNode(testShard2, 'newNode');
127129
netSimVis.setShard(testShard2);
128-
netSimVis.setLocalNode(newNode);
130+
netSimVis.setLocalNode(newNode1);
129131
var newNode2 = createNode(testShard2, 'newNode2');
130132

131133
// Verify: Nodes on new shard have same IDs, different uuids.
132-
assert.equal(myNode.entityID, newNode.entityID);
133-
assert.notEqual(myNode.uuid, newNode.uuid);
134-
assert.equal(node2.entityID, newNode2.entityID);
135-
assert.notEqual(node2.uuid, newNode2.uuid);
136-
137-
// We now have 4 elements; not 5, because the local node is a straight-up
138-
// replacement operation, but we haven't cleaned up the other two nodes
139-
// from the old shard yet.
134+
assert.equal(oldNode1.entityID, newNode1.entityID);
135+
assert.notEqual(oldNode1.uuid, newNode1.uuid);
136+
assert.equal(oldNode2.entityID, newNode2.entityID);
137+
assert.notEqual(oldNode2.uuid, newNode2.uuid);
138+
139+
// We now have 4 elements:
140+
// 1. oldNode2 (dying but not gone)
141+
// 2. oldNode3 (dying but not gone)
142+
// 3. newNode1
143+
// 4. newNode2
144+
// Note that oldNode1 _is_ actually gone, because it was designated as the
145+
// "local" client node before, and the `setLocalNode` operation replaces
146+
// the existing "local" node in the visualization.
140147
assert.equal(4, netSimVis.elements_.length);
141148
assert.equal(2, netSimVis.elements_.filter(function (element) {
142149
return element.isDying();
143150
}).length);
144151

145-
// Render long enough for the tweens to finish and the elements to die
152+
// Render long enough for the "dying" animations on oldNode2 and oldNode3
153+
// to finish.
146154
netSimVis.render({time: 1});
147155
netSimVis.render({time: 1000000});
148-
// Tick to clean up the dead nodes
156+
// Tick to clean up the now-dead nodes.
149157
netSimVis.tick({time: 1});
150158

151159
// Only the two live nodes remain
152160
assert.equal(2, netSimVis.elements_.length);
153-
assert(netSimVis.elements_[0].representsEntity(newNode));
161+
assert(netSimVis.elements_[0].representsEntity(newNode1));
154162
assert(netSimVis.elements_[1].representsEntity(newNode2));
155163
});
156164

0 commit comments

Comments
 (0)