Last active
January 9, 2019 14:27
-
-
Save PCreations/ea2bc0b1c9790878175d176d6ba5a4fa to your computer and use it in GitHub Desktop.
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
const { FooData } = require('./data'); | |
const getFooOfId = (getFooOfIdImpl = async (fooId) => { throw new Error(`Can't retrieved foo of id ${fooId} : missing implementation`) }) => async fooId => { | |
try { | |
const fooData = await getFooOfIdImpl(fooId); | |
return FooData(fooData); | |
} catch (err) { | |
throw new Error(`Unable to retrieve Foo with id ${fooId}`); | |
} | |
} | |
/* | |
This function is used to build a concrete implementation, for example with an in-memory database : | |
const inMemoryFooDatabase = { | |
foo17: { | |
id: 'foo17', | |
foo: 'a foo value', | |
bar: 'a bar value', | |
foobaz: 1234, | |
}, | |
}; | |
const getFooOfIdFromInMemoryDatabase = getFooOfId(fooId => inMemoryFooDatabase[fooId]) | |
*/ | |
module.exports = { | |
getFooOdId, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment