Merge pull request #370 from nasa/open369

[Performance] Fix usages of $interval
This commit is contained in:
akhenry 2015-12-03 18:31:17 -08:00
commit aaeaf3a096
8 changed files with 112 additions and 7 deletions

View File

@ -39,8 +39,11 @@ define(
start = Date.now(); start = Date.now();
function update() { function update() {
var secs = (Date.now() - start) / 1000; var now = Date.now(),
secs = (now - start) / 1000;
displayed = Math.round(digests / secs); displayed = Math.round(digests / secs);
start = now;
digests = 0;
} }
function increment() { function increment() {

View File

@ -204,7 +204,7 @@ define(
// And poll for position changes enforced by styles // And poll for position changes enforced by styles
activeInterval = $interval(function () { activeInterval = $interval(function () {
getSetPosition(getSetPosition()); getSetPosition(getSetPosition());
}, POLLING_INTERVAL, false); }, POLLING_INTERVAL, 0, false);
// ...and stop polling when we're destroyed. // ...and stop polling when we're destroyed.
$scope.$on('$destroy', function () { $scope.$on('$destroy', function () {

View File

@ -0,0 +1,95 @@
/*****************************************************************************
* Open MCT Web, Copyright (c) 2014-2015, United States Government
* as represented by the Administrator of the National Aeronautics and Space
* Administration. All rights reserved.
*
* Open MCT Web is licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* Open MCT Web includes source code licensed under additional open source
* licenses. See the Open Source Licenses file (LICENSES.md) included with
* this source code distribution or the Licensing information page available
* at runtime from the About dialog for additional information.
*****************************************************************************/
/*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine*/
define(
["../../src/directives/MCTSplitPane"],
function (MCTSplitPane) {
'use strict';
var JQLITE_METHODS = [
'on',
'addClass',
'children',
'eq'
];
describe("The mct-split-pane directive", function () {
var mockParse,
mockLog,
mockInterval,
mctSplitPane;
beforeEach(function () {
mockParse = jasmine.createSpy('$parse');
mockLog =
jasmine.createSpyObj('$log', ['warn', 'info', 'debug']);
mockInterval = jasmine.createSpy('$interval');
mockInterval.cancel = jasmine.createSpy('mockCancel');
mctSplitPane = new MCTSplitPane(
mockParse,
mockLog,
mockInterval
);
});
it("is only applicable as an element", function () {
expect(mctSplitPane.restrict).toEqual("E");
});
describe("when its controller is applied", function () {
var mockScope,
mockElement,
testAttrs,
mockChildren,
controller;
beforeEach(function () {
mockScope =
jasmine.createSpyObj('$scope', ['$apply', '$watch', '$on']);
mockElement =
jasmine.createSpyObj('element', JQLITE_METHODS);
testAttrs = {};
mockChildren =
jasmine.createSpyObj('children', JQLITE_METHODS);
mockElement.children.andReturn(mockChildren);
mockChildren.eq.andReturn(mockChildren);
mockChildren[0] = {};
controller = mctSplitPane.controller[3](
mockScope,
mockElement,
testAttrs
);
});
it("sets an interval which does not trigger digests", function () {
expect(mockInterval.mostRecentCall.args[3]).toBe(false);
});
});
});
}
);

View File

@ -19,6 +19,7 @@
"directives/MCTPopup", "directives/MCTPopup",
"directives/MCTResize", "directives/MCTResize",
"directives/MCTScroll", "directives/MCTScroll",
"directives/MCTSplitPane",
"services/Popup", "services/Popup",
"services/PopupService", "services/PopupService",
"services/UrlService", "services/UrlService",

View File

@ -146,6 +146,7 @@ define(
if (canvas.width !== canvas.offsetWidth || if (canvas.width !== canvas.offsetWidth ||
canvas.height !== canvas.offsetHeight) { canvas.height !== canvas.offsetHeight) {
doDraw(scope.draw); doDraw(scope.draw);
scope.$apply();
} }
} }
@ -181,7 +182,7 @@ define(
canvas.addEventListener("webglcontextlost", fallbackFromWebGL); canvas.addEventListener("webglcontextlost", fallbackFromWebGL);
// Check for resize, on a timer // Check for resize, on a timer
activeInterval = $interval(drawIfResized, 1000); activeInterval = $interval(drawIfResized, 1000, 0, false);
// Watch "draw" for external changes to the set of // Watch "draw" for external changes to the set of
// things to be drawn. // things to be drawn.

View File

@ -45,8 +45,10 @@ define(
jasmine.createSpy("$interval"); jasmine.createSpy("$interval");
mockLog = mockLog =
jasmine.createSpyObj("$log", ["warn", "info", "debug"]); jasmine.createSpyObj("$log", ["warn", "info", "debug"]);
mockScope = mockScope = jasmine.createSpyObj(
jasmine.createSpyObj("$scope", ["$watchCollection", "$on"]); "$scope",
["$watchCollection", "$on", "$apply"]
);
mockElement = mockElement =
jasmine.createSpyObj("element", ["find", "html"]); jasmine.createSpyObj("element", ["find", "html"]);
mockInterval.cancel = jasmine.createSpy("cancelInterval"); mockInterval.cancel = jasmine.createSpy("cancelInterval");
@ -152,7 +154,9 @@ define(
// Should track canvas size in an interval // Should track canvas size in an interval
expect(mockInterval).toHaveBeenCalledWith( expect(mockInterval).toHaveBeenCalledWith(
jasmine.any(Function), jasmine.any(Function),
jasmine.any(Number) jasmine.any(Number),
0,
false
); );
// Verify pre-condition // Verify pre-condition

View File

@ -80,7 +80,7 @@ define(
// Update the indicator initially, and start polling. // Update the indicator initially, and start polling.
updateIndicator(); updateIndicator();
$interval(updateIndicator, interval, false); $interval(updateIndicator, interval, 0, false);
} }
ElasticIndicator.prototype.getGlyph = function () { ElasticIndicator.prototype.getGlyph = function () {

View File

@ -55,6 +55,7 @@ define(
expect(mockInterval).toHaveBeenCalledWith( expect(mockInterval).toHaveBeenCalledWith(
jasmine.any(Function), jasmine.any(Function),
testInterval, testInterval,
0,
false false
); );
}); });