[API] Wire in canContain via policy

This commit is contained in:
Victor Woeltjen 2016-08-12 10:24:59 -07:00
parent 1de26d3c5d
commit 831ecc59d9
2 changed files with 37 additions and 2 deletions

View File

@ -2,12 +2,14 @@ define([
'legacyRegistry', 'legacyRegistry',
'./directives/MCTView', './directives/MCTView',
'./services/Instantiate', './services/Instantiate',
'./capabilities/APICapabilityDecorator' './capabilities/APICapabilityDecorator',
'./policies/AdapterCompositionPolicy'
], function ( ], function (
legacyRegistry, legacyRegistry,
MCTView, MCTView,
Instantiate, Instantiate,
APICapabilityDecorator APICapabilityDecorator,
AdapterCompositionPolicy
) { ) {
legacyRegistry.register('src/adapter', { legacyRegistry.register('src/adapter', {
"extensions": { "extensions": {
@ -42,6 +44,13 @@ define([
"$injector" "$injector"
] ]
} }
],
policies: [
{
category: "composition",
implementation: AdapterCompositionPolicy,
depends: [ "mct" ]
}
] ]
} }
}); });

View File

@ -0,0 +1,26 @@
define([], function () {
function AdapterCompositionPolicy(mct) {
this.mct = mct;
}
AdapterCompositionPolicy.prototype.allow = function (
containerType,
childType
) {
var containerObject = containerType.getInitialModel();
var childObject = childType.getInitialModel();
containerObject.type = containerType.getKey();
childObject.type = childType.getKey();
var composition = mct.Composition(containerObject);
if (composition) {
return composition.canContain(childObject);
}
return true;
};
return AdapterCompositionPolicy;
});