Last active
March 22, 2018 12:45
-
-
Save DmitryMasley/d20aabb2054f7142666c630ceed92c29 to your computer and use it in GitHub Desktop.
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
// returns collection with identifer `id` | |
const getStrings = () => { | |
return new Promise((resolve) => { | |
resolve([ | |
{ | |
id: "id", | |
sourceString: "{1} word" | |
} | |
]) | |
}); | |
} | |
// accepts an array of ids, returns collection | |
const getPlaceholders = (stringIds) => { | |
return new Promise((resolve) => { | |
resolve(stringIds.map(id => ({id, placeholders: []}))) | |
}); | |
} | |
// accepts array of ids, returns collection | |
const getKeys = (stringIds) => { | |
return new Promise((resolve) => { | |
resolve(stringIds.map(id => ({id, key: "key"}))) | |
}); | |
} | |
// returns { strings, placeholders, keys } | |
// get strings first, than using their ids make requests to keys and placeholders (parallely of course) | |
// return all three collections in one object | |
// if getKeys gets rejected still return resolved promise with { strings, placeholders, keys: [] } | |
const getStringData = () => { | |
return new Promise((resolve) => { | |
getStrings().then((strings) => { | |
resolve(strings); | |
}) | |
}) | |
.then((strings) => { | |
return getPlaceholders(strings) | |
.then(getKeys(strings)) | |
}) | |
.then((strings, placeholders, keys) => { | |
return Promise.resolve({ strings, placeholders, keys }); | |
}) | |
} | |
// task is to implement getStringData as described above, current implementaion is not correct | |
// can be done with Promises or async/await syntax |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment