* 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

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;