mirror of
https://github.com/nasa/openmct.git
synced 2025-03-12 23:44:08 +00:00
[Representation] Pass attributes one way
Instead of two-way binding attributes, only pass them in from the parent scope. This permits users of mct-include to use one-time binding to reduce watch counts (two-way binding across an isolate scope does not permit this.) https://github.com/nasa/openmctweb/issues/314
This commit is contained in:
parent
3fd4304de1
commit
cfb6d4ccbf
@ -57,15 +57,30 @@ define(
|
|||||||
function MCTInclude(templates, templateLinker) {
|
function MCTInclude(templates, templateLinker) {
|
||||||
var templateMap = {};
|
var templateMap = {};
|
||||||
|
|
||||||
function link(scope, element) {
|
function link(scope, element, attrs) {
|
||||||
var changeTemplate = templateLinker.link(
|
var parent = scope.$parent,
|
||||||
scope,
|
key = parent.$eval(attrs.key),
|
||||||
element,
|
changeTemplate = templateLinker.link(
|
||||||
scope.key && templateMap[scope.key]
|
scope,
|
||||||
);
|
element,
|
||||||
|
key && templateMap[key]
|
||||||
|
),
|
||||||
|
unwatches = [];
|
||||||
|
|
||||||
scope.$watch('key', function (key) {
|
unwatches = ["ngModel", "parameters"].map(function (attr) {
|
||||||
|
return parent.$watch(attrs[attr], function (value) {
|
||||||
|
scope[attr] = value;
|
||||||
|
}, true);
|
||||||
|
});
|
||||||
|
|
||||||
|
unwatches.push(parent.$watch(attrs.key, function (key) {
|
||||||
changeTemplate(key && templateMap[key]);
|
changeTemplate(key && templateMap[key]);
|
||||||
|
}));
|
||||||
|
|
||||||
|
scope.$on("$destroy", function () {
|
||||||
|
unwatches.forEach(function (unwatch) {
|
||||||
|
unwatch();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,10 +100,7 @@ define(
|
|||||||
link: link,
|
link: link,
|
||||||
|
|
||||||
// May hide the element, so let other directives act first
|
// May hide the element, so let other directives act first
|
||||||
priority: -1000,
|
priority: -1000
|
||||||
|
|
||||||
// Two-way bind key, ngModel, and parameters
|
|
||||||
scope: { key: "=", ngModel: "=", parameters: "=" }
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user