From 831ecc59d91ea29578aaa3524f3f411e8c9e2a12 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Fri, 12 Aug 2016 10:24:59 -0700 Subject: [PATCH] [API] Wire in canContain via policy --- src/adapter/bundle.js | 13 ++++++++-- .../policies/AdapterCompositionPolicy.js | 26 +++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 src/adapter/policies/AdapterCompositionPolicy.js diff --git a/src/adapter/bundle.js b/src/adapter/bundle.js index 30c18594ec..4483658c90 100644 --- a/src/adapter/bundle.js +++ b/src/adapter/bundle.js @@ -2,12 +2,14 @@ define([ 'legacyRegistry', './directives/MCTView', './services/Instantiate', - './capabilities/APICapabilityDecorator' + './capabilities/APICapabilityDecorator', + './policies/AdapterCompositionPolicy' ], function ( legacyRegistry, MCTView, Instantiate, - APICapabilityDecorator + APICapabilityDecorator, + AdapterCompositionPolicy ) { legacyRegistry.register('src/adapter', { "extensions": { @@ -42,6 +44,13 @@ define([ "$injector" ] } + ], + policies: [ + { + category: "composition", + implementation: AdapterCompositionPolicy, + depends: [ "mct" ] + } ] } }); diff --git a/src/adapter/policies/AdapterCompositionPolicy.js b/src/adapter/policies/AdapterCompositionPolicy.js new file mode 100644 index 0000000000..c9730a5393 --- /dev/null +++ b/src/adapter/policies/AdapterCompositionPolicy.js @@ -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; +});