By using a common
module (we can name it whatever we want), we make dependencies explicit, reduce unnecessary documentation, and avoid polluting the global namespace.
Created
November 20, 2014 16:52
-
-
Save kyriesent/cbe413d2a1323334aac1 to your computer and use it in GitHub Desktop.
Using Proxy Module instead of Globals
This file contains hidden or 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
# .. Start express app | |
app = createExpressApp() | |
require('./routes') app |
This file contains hidden or 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
common = module.exports | |
common.models = require './models' | |
common.controllers = require './controllers' |
This file contains hidden or 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
module.exports = | |
students: require './students.controller' |
This file contains hidden or 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
module.exports = | |
Student: require './student' |
This file contains hidden or 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
common = require '../common' | |
module.exports = (webapp) -> | |
app.get '/student/:_id', -> | |
common.controllers.students.view req.params._id |
This file contains hidden or 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
common = require '../common' # this will replace using global.models and keep our dependencies clear | |
module.exports = | |
view: -> | |
# ... do stuff | |
return common.models.Student.view |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment