Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Revisit decision to forward previous value #31

@briancavalier

Description

@briancavalier

Early on, I made a decision that when a handler returned undefined, the previous promise value should be forwarded through to the next promise. That's convenient in some cases, as it allows reusing and writing handlers that have no return statement.

However, it means that it's easy to get into trouble when doing things like this:

when(somethingHappens, function(result) {
    return result["thePropertyIReallyCareAbout"];
}).then(handleProperty);

In cases like that, where the first handler legitimately needs to return undefined, and we want handleProperty to receive undefined, it will instead receive result, which is just plain wrong. Right now, the workaround is:

when(somethingHappens, function(result) {
    return result["thePropertyIReallyCareAbout"] || null;
}).then(handleProperty);

which is ok, but probably would cause someone a real headache trying to figure it out, and means that handleProperty receives null instead of undefined.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions