Skip to content

Commit 54a1cf3

Browse files
committed
track explicit properties, remove duplicate tracking of observables
1 parent a4eacfd commit 54a1cf3

File tree

1 file changed

+84
-44
lines changed

1 file changed

+84
-44
lines changed

Source/Widgets/CesiumInspector/CesiumInspectorViewModel.js

+84-44
Original file line numberDiff line numberDiff line change
@@ -104,176 +104,176 @@ define([
104104
* @type {Boolean}
105105
* @default false
106106
*/
107-
this.frustums = knockout.observable(false);
107+
this.frustums = false;
108108

109109
/**
110110
* Gets or sets the show performance display state. This property is observable.
111111
* @type {Boolean}
112112
* @default false
113113
*/
114-
this.performance = knockout.observable(false);
114+
this.performance = false;
115115

116116
/**
117117
* Gets or sets the shader cache text. This property is observable.
118118
* @type {String}
119119
* @default ''
120120
*/
121-
this.shaderCacheText = knockout.observable('');
121+
this.shaderCacheText = '';
122122

123123
/**
124124
* Gets or sets the show primitive bounding sphere state. This property is observable.
125125
* @type {Boolean}
126126
* @default false
127127
*/
128-
this.primitiveBoundingSphere = knockout.observable(false);
128+
this.primitiveBoundingSphere = false;
129129

130130
/**
131131
* Gets or sets the show primitive reference frame state. This property is observable.
132132
* @type {Boolean}
133133
* @default false
134134
*/
135-
this.primitiveReferenceFrame = knockout.observable(false);
135+
this.primitiveReferenceFrame = false;
136136

137137
/**
138138
* Gets or sets the filter primitive state. This property is observable.
139139
* @type {Boolean}
140140
* @default false
141141
*/
142-
this.filterPrimitive = knockout.observable(false);
142+
this.filterPrimitive = false;
143143

144144
/**
145145
* Gets or sets the show tile bounding sphere state. This property is observable.
146146
* @type {Boolean}
147147
* @default false
148148
*/
149-
this.tileBoundingSphere = knockout.observable(false);
149+
this.tileBoundingSphere = false;
150150

151151
/**
152152
* Gets or sets the filter tile state. This property is observable.
153153
* @type {Boolean}
154154
* @default false
155155
*/
156-
this.filterTile = knockout.observable(false);
156+
this.filterTile = false;
157157

158158
/**
159159
* Gets or sets the show wireframe state. This property is observable.
160160
* @type {Boolean}
161161
* @default false
162162
*/
163-
this.wireframe = knockout.observable(false);
163+
this.wireframe = false;
164164

165165
/**
166166
* Gets or sets the show globe depth state. This property is observable.
167167
* @type {Boolean}
168168
* @default false
169169
*/
170-
this.globeDepth = knockout.observable(false);
170+
this.globeDepth = false;
171171

172172
/**
173173
* Gets or sets the show pick depth state. This property is observable.
174174
* @type {Boolean}
175175
* @default false
176176
*/
177-
this.pickDepth = knockout.observable(false);
177+
this.pickDepth = false;
178178

179179
/**
180180
* Gets or sets the index of the depth frustum to display. This property is observable.
181181
* @type {Number}
182182
* @default 1
183183
*/
184-
this.depthFrustum = knockout.observable(1);
184+
this.depthFrustum = 1;
185185
this._numberOfFrustums = 1;
186186

187187
/**
188188
* Gets or sets the suspend updates state. This property is observable.
189189
* @type {Boolean}
190190
* @default false
191191
*/
192-
this.suspendUpdates = knockout.observable(false);
192+
this.suspendUpdates = false;
193193

194194
/**
195195
* Gets or sets the show tile coordinates state. This property is observable.
196196
* @type {Boolean}
197197
* @default false
198198
*/
199-
this.tileCoordinates = knockout.observable(false);
199+
this.tileCoordinates = false;
200200

201201
/**
202202
* Gets or sets the frustum statistic text. This property is observable.
203203
* @type {String}
204204
* @default ''
205205
*/
206-
this.frustumStatisticText = knockout.observable('');
206+
this.frustumStatisticText = false;
207207

208208
/**
209209
* Gets or sets the selected tile information text. This property is observable.
210210
* @type {String}
211211
* @default ''
212212
*/
213-
this.tileText = knockout.observable('');
213+
this.tileText = '';
214214

215215
/**
216216
* Gets if a primitive has been selected. This property is observable.
217217
* @type {Boolean}
218218
* @default false
219219
*/
220-
this.hasPickedPrimitive = knockout.observable(false);
220+
this.hasPickedPrimitive = false;
221221

222222
/**
223223
* Gets if a tile has been selected. This property is observable
224224
* @type {Boolean}
225225
* @default false
226226
*/
227-
this.hasPickedTile = knockout.observable(false);
227+
this.hasPickedTile = false;
228228

229229
/**
230230
* Gets if the picking primitive command is active. This property is observable.
231231
* @type {Boolean}
232232
* @default false
233233
*/
234-
this.pickPrimitiveActive = knockout.observable(false);
234+
this.pickPrimitiveActive = false;
235235

236236
/**
237237
* Gets if the picking tile command is active. This property is observable.
238238
* @type {Boolean}
239239
* @default false
240240
*/
241-
this.pickTileActive = knockout.observable(false);
241+
this.pickTileActive = false;
242242

243243
/**
244244
* Gets or sets if the cesium inspector drop down is visible. This property is observable.
245245
* @type {Boolean}
246246
* @default true
247247
*/
248-
this.dropDownVisible = knockout.observable(true);
248+
this.dropDownVisible = true;
249249

250250
/**
251251
* Gets or sets if the general section is visible. This property is observable.
252252
* @type {Boolean}
253253
* @default true
254254
*/
255-
this.generalVisible = knockout.observable(true);
255+
this.generalVisible = true;
256256

257257
/**
258258
* Gets or sets if the primitive section is visible. This property is observable.
259259
* @type {Boolean}
260260
* @default false
261261
*/
262-
this.primitivesVisible = knockout.observable(false);
262+
this.primitivesVisible = false;
263263

264264
/**
265265
* Gets or sets if the terrain section is visible. This property is observable.
266266
* @type {Boolean}
267267
* @default false
268268
*/
269-
this.terrainVisible = knockout.observable(false);
269+
this.terrainVisible = false;
270270

271271
/**
272272
* Gets or sets the index of the depth frustum text. This property is observable.
273273
* @type {String}
274-
* @default '1 of 1'
274+
* @default ''
275275
*/
276-
this.depthFrustumText = knockout.observable('1 of 1');
276+
this.depthFrustumText = '';
277277

278278
/**
279279
* Gets the text on the general section expand button. This property is computed.
@@ -302,6 +302,34 @@ define([
302302
return that.terrainVisible ? '-' : '+';
303303
});
304304

305+
knockout.track(this, [
306+
'frustums',
307+
'performance',
308+
'shaderCacheText',
309+
'primitiveBoundingSphere',
310+
'primitiveReferenceFrame',
311+
'filterPrimitive',
312+
'tileBoundingSphere',
313+
'filterTile',
314+
'wireframe',
315+
'globeDepth',
316+
'pickDepth',
317+
'depthFrustum',
318+
'suspendUpdates',
319+
'tileCoordinates',
320+
'frustumStatisticText',
321+
'tileText',
322+
'hasPickedPrimitive',
323+
'hasPickedTile',
324+
'pickPrimitiveActive',
325+
'pickTileActive',
326+
'dropDownVisible',
327+
'generalVisible',
328+
'primitivesVisible',
329+
'terrainVisible',
330+
'depthFrustumText'
331+
]);
332+
305333
this._toggleDropDown = createCommand(function() {
306334
that.dropDownVisible = !that.dropDownVisible;
307335
});
@@ -318,11 +346,11 @@ define([
318346
that.terrainVisible = !that.terrainVisible;
319347
});
320348

321-
this.frustums.subscribe(function(val) {
349+
this._frustumsSubscription = knockout.getObservable(this, 'frustums').subscribe(function(val) {
322350
that._scene.debugShowFrustums = val;
323351
});
324352

325-
this.performance.subscribe(function(val) {
353+
this._performanceSubscriptioin = knockout.getObservable(this, 'performance').subscribe(function(val) {
326354
if (val) {
327355
that._performanceDisplay = new PerformanceDisplay({
328356
container : that._performanceContainer
@@ -337,7 +365,7 @@ define([
337365
return true;
338366
});
339367

340-
this.primitiveBoundingSphere.subscribe(function() {
368+
this._primitiveBoundingSphereSubscription = knockout.getObservable(this, 'primitiveBoundingSphere').subscribe(function() {
341369
that._showPrimitiveBoundingSphere();
342370
});
343371

@@ -355,7 +383,7 @@ define([
355383
return true;
356384
});
357385

358-
this.primitiveReferenceFrame.subscribe(function() {
386+
this._primitiveReferenceFrameSubscription = knockout.getObservable(this, 'primitiveReferenceFrame').subscribe(function() {
359387
that._showPrimitiveReferenceFrame();
360388
});
361389

@@ -375,23 +403,23 @@ define([
375403
return true;
376404
});
377405

378-
this.filterPrimitive.subscribe(function() {
406+
this._filterPrimitiveSubscription = knockout.getObservable(this, 'filterPrimitive').subscribe(function() {
379407
that._doFilterPrimitive();
380408
});
381409

382-
this.wireframe.subscribe(function(val) {
410+
this._wireframeSubscription = knockout.getObservable(this, 'wireframe').subscribe(function(val) {
383411
globe._surface.tileProvider._debug.wireframe = val;
384412
});
385413

386-
this.globeDepth.subscribe(function(val) {
414+
this._globeDepthSubscription = knockout.getObservable(this, 'globeDepth').subscribe(function(val) {
387415
that._scene.debugShowGlobeDepth = val;
388416
});
389417

390-
this.pickDepth.subscribe(function(val) {
418+
this._pickDepthSubscription = knockout.getObservable(this, 'pickDepth').subscribe(function(val) {
391419
that._scene.debugShowPickDepth = val;
392420
});
393421

394-
this.depthFrustum.subscribe(function(val) {
422+
this._depthFrustumSubscription = knockout.getObservable(this, 'depthFrustum').subscribe(function(val) {
395423
that.scene.debugShowDepthFrustum = val;
396424
});
397425

@@ -407,7 +435,7 @@ define([
407435
return true;
408436
});
409437

410-
this.suspendUpdates.subscribe(function(val) {
438+
this._suspendUpdatesSubscription = knockout.getObservable(this, 'suspendUpdates').subscribe(function(val) {
411439
globe._surface._debug.suspendLodUpdate = val;
412440
if (!val) {
413441
that.filterTile = false;
@@ -427,11 +455,11 @@ define([
427455
return true;
428456
});
429457

430-
this.tileCoordinates.subscribe(function() {
458+
this._tileCoordinatesSubscription = knockout.getObservable(this, 'tileCoordinates').subscribe(function() {
431459
that._showTileCoordinates();
432460
});
433461

434-
this.tileBoundingSphere.subscribe(function() {
462+
this._tileBoundingSphereSubscription = knockout.getObservable(this, 'tileBoundingSphere').subscribe(function() {
435463
that._showTileBoundingSphere();
436464
});
437465

@@ -444,7 +472,6 @@ define([
444472
return true;
445473
});
446474

447-
448475
this._doFilterTile = createCommand(function() {
449476
if (!that.filterTile) {
450477
that.suspendUpdates = false;
@@ -460,7 +487,7 @@ define([
460487
return true;
461488
});
462489

463-
this.filterTile.subscribe(function() {
490+
this._filterTileSubscription = knockout.getObservable(this, 'filterTile').subscribe(function() {
464491
that.doFilterTile();
465492
});
466493

@@ -480,7 +507,7 @@ define([
480507
that.pickPrimitiveActive = !that.pickPrimitiveActive;
481508
});
482509

483-
this.pickPrimitiveActive.subscribe(function(val) {
510+
this._pickPrimitiveActiveSubscription = knockout.getObservable(this, 'pickPrimitiveActive').subscribe(function(val) {
484511
if (val) {
485512
eventHandler.setInputAction(pickPrimitive, ScreenSpaceEventType.LEFT_CLICK);
486513
} else {
@@ -523,15 +550,13 @@ define([
523550
that.pickTileActive = !that.pickTileActive;
524551
});
525552

526-
this.pickTileActive.subscribe(function(val) {
553+
this._pickTileActiveSubscription = knockout.getObservable(this, 'pickTileActive').subscribe(function(val) {
527554
if (val) {
528555
eventHandler.setInputAction(selectTile, ScreenSpaceEventType.LEFT_CLICK);
529556
} else {
530557
eventHandler.removeInputAction(ScreenSpaceEventType.LEFT_CLICK);
531558
}
532559
});
533-
534-
knockout.track(this);
535560
}
536561

537562
defineProperties(CesiumInspectorViewModel.prototype, {
@@ -913,6 +938,21 @@ define([
913938
*/
914939
CesiumInspectorViewModel.prototype.destroy = function() {
915940
this._eventHandler.destroy();
941+
this._frustumsSubscription.dispose();
942+
this._performanceSubscriptioin.dispose();
943+
this._primitiveBoundingSphereSubscription.dispose();
944+
this._primitiveReferenceFrameSubscription.dispose();
945+
this._filterPrimitiveSubscription.dispose();
946+
this._wireframeSubscription.dispose();
947+
this._globeDepthSubscription.dispose();
948+
this._pickDepthSubscription.dispose();
949+
this._depthFrustumSubscription.dispose();
950+
this._suspendUpdatesSubscription.dispose();
951+
this._tileCoordinatesSubscription.dispose();
952+
this._tileBoundingSphereSubscription.dispose();
953+
this._filterTileSubscription.dispose();
954+
this._pickPrimitiveActiveSubscription.dispose();
955+
this._pickTileActiveSubscription.dispose();
916956
return destroyObject(this);
917957
};
918958

0 commit comments

Comments
 (0)