mirror of
https://github.com/nasa/openmct.git
synced 2025-01-31 08:25:31 +00:00
Merge pull request #1127 from nasa/console-warning-1114
[Tree] Check for change before scope.$apply
This commit is contained in:
commit
9063996e84
@ -28,8 +28,10 @@ define([
|
|||||||
function link(scope, element) {
|
function link(scope, element) {
|
||||||
var treeView = new TreeView(gestureService),
|
var treeView = new TreeView(gestureService),
|
||||||
unobserve = treeView.observe(function (domainObject) {
|
unobserve = treeView.observe(function (domainObject) {
|
||||||
|
if (scope.mctModel !== domainObject) {
|
||||||
scope.mctModel = domainObject;
|
scope.mctModel = domainObject;
|
||||||
scope.$apply();
|
scope.$apply();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
element.append(angular.element(treeView.elements()));
|
element.append(angular.element(treeView.elements()));
|
||||||
|
@ -29,6 +29,18 @@ define([
|
|||||||
mockExpr,
|
mockExpr,
|
||||||
mctTree;
|
mctTree;
|
||||||
|
|
||||||
|
function makeMockDomainObject(id) {
|
||||||
|
var mockDomainObject = jasmine.createSpyObj('domainObject-' + id, [
|
||||||
|
'getId',
|
||||||
|
'getModel',
|
||||||
|
'getCapability',
|
||||||
|
'hasCapability'
|
||||||
|
]);
|
||||||
|
mockDomainObject.getId.andReturn(id);
|
||||||
|
mockDomainObject.getModel.andReturn({});
|
||||||
|
return mockDomainObject;
|
||||||
|
}
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
mockGestureService = jasmine.createSpyObj(
|
mockGestureService = jasmine.createSpyObj(
|
||||||
'gestureService',
|
'gestureService',
|
||||||
@ -56,7 +68,8 @@ define([
|
|||||||
testAttrs;
|
testAttrs;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
mockScope = jasmine.createSpyObj('$scope', ['$watch', '$on']);
|
mockScope =
|
||||||
|
jasmine.createSpyObj('$scope', ['$watch', '$on', '$apply']);
|
||||||
mockElement = jasmine.createSpyObj('element', ['append']);
|
mockElement = jasmine.createSpyObj('element', ['append']);
|
||||||
testAttrs = { mctModel: "some-expression" };
|
testAttrs = { mctModel: "some-expression" };
|
||||||
mockScope.$parent =
|
mockScope.$parent =
|
||||||
@ -88,6 +101,27 @@ define([
|
|||||||
jasmine.any(Function)
|
jasmine.any(Function)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// https://github.com/nasa/openmct/issues/1114
|
||||||
|
it("does not trigger $apply during $watches", function () {
|
||||||
|
mockScope.mctObject = makeMockDomainObject('root');
|
||||||
|
mockScope.mctMode = makeMockDomainObject('selection');
|
||||||
|
mockScope.$watch.calls.forEach(function (call) {
|
||||||
|
call.args[1](mockScope[call.args[0]]);
|
||||||
|
});
|
||||||
|
expect(mockScope.$apply).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
it("does trigger $apply from other value changes", function () {
|
||||||
|
// White-boxy; we know this is the setter for the tree's value
|
||||||
|
var treeValueFn = mockScope.$watch.calls[0].args[1];
|
||||||
|
|
||||||
|
mockScope.mctObject = makeMockDomainObject('root');
|
||||||
|
mockScope.mctMode = makeMockDomainObject('selection');
|
||||||
|
|
||||||
|
treeValueFn(makeMockDomainObject('other'));
|
||||||
|
|
||||||
|
expect(mockScope.$apply).toHaveBeenCalled();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user