Created
September 23, 2014 23:40
-
-
Save jstrimpel/968601bf5ffeb8835504 to your computer and use it in GitHub Desktop.
lazo: base controller that loads data before executing action
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// application base controller that resides at app/ctl.js | |
define(['lazoCtl'], function (LazoCtl) { | |
'use strict'; | |
return LazoCtl.extend({ | |
models: ['defaultModel1', 'defaultModel2'], | |
loadModels: function (callback) { | |
for (var i = 0; i < models.length; i++) { | |
(function (i){ | |
// call this.loadModel for each model in this.models | |
// then execute callback passing error or success accordingly | |
callback(null, true); // node style callback | |
})(i); | |
} | |
}, | |
index: function (options) { | |
var self = this; | |
this.loadModels(function (err, success) { | |
if (err) { | |
return options.error(err); | |
} | |
options.success('index'); | |
}); | |
} | |
}); | |
}); | |
// use base controller | |
define(['app/ctl'], function (BaseCtl) { | |
return BaseCtl.extend({ | |
// override base property | |
// if you still want to load the default models | |
// then do this instead: BaseCtl.prototype.slice(0).concat(['differentModel1', 'differentModel2', 'differentModel3']) | |
models: ['differentModel1', 'differentModel2', 'differentModel3'], | |
// optional; only needed if you want to do something before | |
// calling the index action | |
index: function (options) { | |
this.loadModels(function (err, success) { | |
if (err) { | |
return options.error(err); | |
} | |
options.success('index'); | |
}); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment