[API] Add MCTView directive as an adapter

This commit is contained in:
Victor Woeltjen 2016-05-27 16:19:20 -07:00
parent a07e2fb8e5
commit 136f2ae785
3 changed files with 59 additions and 0 deletions

View File

@ -21,6 +21,13 @@ define([
this.legacyBundle.extensions.types =
this.legacyBundle.extensions.types || [];
this.legacyBundle.extensions.types.push(legacyDef);
var viewFactory = type.view(this.regions.main);
if (viewFactory) {
this.legacyBundle.extensions.views =
this.legacyBundle.extensions.views || [];
}
};
MCT.prototype.start = function () {
@ -28,5 +35,9 @@ define([
this.emit('start');
};
MCT.prototype.regions = {
main: "MAIN"
};
return MCT;
});

View File

@ -0,0 +1,40 @@
define(function () {
function MCTView(newViews) {
var factories = {};
newViews.forEach(function (newView) {
factories[newView.key] = newView.factory;
});
return {
restrict: 'A',
link: function (scope, element, attrs) {
var key = undefined;
var mctObject = undefined;
function maybeShow() {
if (!factories[key]) {
return;
}
if (!mctObject) {
return;
}
var view = factories[key](mctObject);
var elements = view.elements;
element.empty();
element.append(elements);
}
scope.$watch('key', setKey);
scope.$watch('mctObject', setObject);
},
scope: {
key: "=",
mctObject: "="
}
};
}
return MCTView;
});

View File

@ -15,8 +15,16 @@ define(function () {
*/
function Type(definition) {
this.definition = definition;
this.views = {};
}
Type.prototype.view = function (region, factory) {
if (arguments.length > 1) {
this.views[region] = factory;
}
return this.views[region];
};
/**
* Get a definition for this type that can be registered using the
* legacy bundle format.