Created
May 5, 2016 13:55
-
-
Save leemason/76c27eb6bc8173de5bce31fd99674864 to your computer and use it in GitHub Desktop.
Facade/Implicit Invocation
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
let DB = require('db_facade'); | |
// Now you can use DB as its already created, this means we dont need to create it everywhere we use it. | |
export default class Controller{ | |
postIndex(req, res){ | |
DB.insert('table', req.get('data')); | |
} | |
} |
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
let db = require('db_module'), | |
config = require('config'); | |
let DB = new db(config.db); | |
export default DB; |
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
//example of a module that needs "something" to be given for its usage | |
export default class DB{ | |
constructor(config){ | |
this.config = config; | |
} | |
select(){ | |
// select code | |
} | |
insert(){ | |
// insert | |
} | |
// etc | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment