-
-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What's the reasoning behind the "no-nesting" rule? #42
Comments
Be good add option |
@EvgenyOrekhov great question thanks! These rules definitely don't represent the best or the only way to make promises, but in my experience when I've found myself nesting inside of If you can use async/await you'd probably want to do this let object = await database.read({id: 123})
await database.update(object)
await transport.respond(object) If you cannot function updateDB(data) {
return db.update(data).then(function(success) {
if (!success) throw new Error('Could not write to DB properly')
return data
})
} Then you can write some super tight promise like this: return database.read({id: 123})
.then(mutateObject)
.then(updateDB)
.then(transport.respond)
.catch(transport.error); There are 100 ways to write promises and in general if you have a success/fail situation instead of returning a boolean you might want to This might not work for you, so in that cases you don't need the rule. |
I constrained myself to the "JSLint" subset of JavaScript which doesn't allow |
If you use a promise library (like Bluebird or Q) it likely has the return database
.read({id: 123})
.tap(function (object) {
/* ... code that changes the object ... */
return database.update(object);
})
.then(transport.respond) // transport.respond will receive the object
.catch(transport.error); |
Can someone please help me to fix the no-nesting promises warning with this method? Here is the code:
There are two lines ... marked // avoid nesting problems that are causing the warnings. Please help as what I have done doesn't seem to work. |
I can't wrap my head around on how to not nest my thens.
How can I not nest here?
The text was updated successfully, but these errors were encountered: