Created
August 22, 2019 22:58
-
-
Save heisian/8ccbaf928dfb65e756fed7b39ce0c44d to your computer and use it in GitHub Desktop.
Coalescing imports/exports w/o Repeating Yourself (too much)
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
const Redis = require('ioredis') | |
const services = require('./services') | |
const redis = new Redis() | |
;(() => { | |
const oneInstance = new services.One() | |
const one = oneInstance.getNumberOne() | |
services.two.validate(one) | |
const two = services.two.calculate(one) | |
const three = services.three(redis) | |
three.setNumber('TWO', two) | |
})() |
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 = { | |
one: class One { | |
getNumberOne() { | |
return 1 | |
} | |
} | |
} |
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 = { | |
three: (redis) => { | |
return { | |
setNumber: (key, data) => { | |
if (typeof data === 'number') { | |
redis.set(key, 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
module.exports = { | |
two: { | |
validate: function validateTwoInput(input) { | |
if (typeof input !== 'number') throw new Error('Input must be a number!') | |
} | |
calculate: (input) => { | |
return 1 + input | |
} | |
} | |
} |
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 = { | |
...require('lib/src/one'), | |
...require('lib/src/two'), | |
...require('lib/src/three'), | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment