Last active
September 4, 2017 14:48
-
-
Save mpj/8c20ed273e8a0331958f69b827c77741 to your computer and use it in GitHub Desktop.
di example
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 createGetUserName = require('./di-lib.js') | |
const getUsername = createGetUserName(database) | |
getUserName(1).then(name => console.log('the name of user 1 is', name)) |
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
// notice: no require statement! | |
function createGetUserName(database) { | |
return function getUserName(id) { | |
return db.table('users').load(id) | |
.then(user => user.name) | |
} | |
} | |
module.exports = createGetUserName |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment