* Use mixin class for ViewController management

This commit is contained in:
Bryan Ashby 2015-08-12 17:26:05 -06:00
parent bfdc58b90c
commit 40e1e1bea8
3 changed files with 40 additions and 20 deletions

View File

@ -40,13 +40,7 @@ function FullScreenEditor(options) {
this.editorMode = 'edit'; // view | edit | editMenu | this.editorMode = 'edit'; // view | edit | editMenu |
// :TODO: viewControllers management should be a mixin that can be thrown in here, menu_module.js, etc. this.initViewControllers();
this.viewControllers = {};
this.addViewController = function(name, vc) {
assert(!self.viewControllers[name]);
self.viewControllers[name] = vc;
return vc;
}
this.getFooterName = function(editorMode) { this.getFooterName = function(editorMode) {
editorMode = editorMode || this.editorMode; editorMode = editorMode || this.editorMode;
@ -133,8 +127,9 @@ function FullScreenEditor(options) {
}, },
function displayFooter(callback) { function displayFooter(callback) {
// we have to treat the footer special // we have to treat the footer special
self.redrawFooter( { clear : false, footerName : self.getFooterName() }, function footerDisplayed(err) { var footerName = self.getFooterName();
if(self.initMci) { self.redrawFooter( { clear : false, footerName : footerName }, function footerDisplayed(err, artData) {
if(options.initMci) {
self.mciData[footerName] = artData; self.mciData[footerName] = artData;
} }
callback(err); callback(err);
@ -271,6 +266,7 @@ function FullScreenEditor(options) {
} }
require('util').inherits(FullScreenEditor, events.EventEmitter); require('util').inherits(FullScreenEditor, events.EventEmitter);
require('./mod_mixins.js').ViewControllerManagement.call(FullScreenEditor.prototype);
FullScreenEditor.prototype.enter = function() { FullScreenEditor.prototype.enter = function() {

View File

@ -24,7 +24,8 @@ function MenuModule(options) {
this.menuConfig = options.menuConfig; this.menuConfig = options.menuConfig;
this.menuConfig.options = options.menuConfig.options || {}; this.menuConfig.options = options.menuConfig.options || {};
this.menuMethods = {}; // methods called from @method's this.menuMethods = {}; // methods called from @method's
this.viewControllers = {}; // name->vc
this.initViewControllers();
this.initSequence = function() { this.initSequence = function() {
var mciData = { }; var mciData = { };
@ -142,6 +143,8 @@ function MenuModule(options) {
require('util').inherits(MenuModule, PluginModule); require('util').inherits(MenuModule, PluginModule);
require('./mod_mixins.js').ViewControllerManagement.call(MenuModule.prototype);
MenuModule.prototype.enter = function(client) { MenuModule.prototype.enter = function(client) {
this.client = client; this.client = client;
assert(_.isObject(client)); assert(_.isObject(client));
@ -150,16 +153,7 @@ MenuModule.prototype.enter = function(client) {
}; };
MenuModule.prototype.leave = function() { MenuModule.prototype.leave = function() {
var self = this; this.detachViewControllers();
Object.keys(this.viewControllers).forEach(function entry(name) {
self.viewControllers[name].detachClientEvents();
});
};
MenuModule.prototype.addViewController = function(name, vc) {
assert(!this.viewControllers[name]);
this.viewControllers[name] = vc;
return vc;
}; };
MenuModule.prototype.beforeArt = function() { MenuModule.prototype.beforeArt = function() {

30
core/mod_mixins.js Normal file
View File

@ -0,0 +1,30 @@
/* jslint node: true */
'use strict';
var assert = require('assert');
//
// A simple mixin for View Controller management
//
var ViewControllerManagement = function() {
this.initViewControllers = function() {
this.viewControllers = {};
};
this.detachViewControllers = function() {
var self = this;
Object.keys(this.viewControllers).forEach(function vc(name) {
self.viewControllers[name].detachClientEvents();
});
};
this.addViewController = function(name, vc) {
assert(this.viewControllers, 'initViewControllers() has not been called!');
assert(!this.viewControllers[name], 'ViewController by the name of \'' + name + '\' already exists!');
this.viewControllers[name] = vc;
return vc;
};
};
exports.ViewControllerManagement = ViewControllerManagement;