{"action":"created","issue":{"url":"https://api.github.com/repos/pburtchaell/redux-promise-middleware/issues/71","repository_url":"https://api.github.com/repos/pburtchaell/redux-promise-middleware","labels_url":"https://api.github.com/repos/pburtchaell/redux-promise-middleware/issues/71/labels{/name}","comments_url":"https://api.github.com/repos/pburtchaell/redux-promise-middleware/issues/71/comments","events_url":"https://api.github.com/repos/pburtchaell/redux-promise-middleware/issues/71/events","html_url":"https://github.com/pburtchaell/redux-promise-middleware/issues/71","id":149164057,"number":71,"title":"Original promise can be returned to avoid anti-pattern","user":{"login":"Willyham","id":169475,"avatar_url":"https://avatars.githubusercontent.com/u/169475?v=3","gravatar_id":"","url":"https://api.github.com/users/Willyham","html_url":"https://github.com/Willyham","followers_url":"https://api.github.com/users/Willyham/followers","following_url":"https://api.github.com/users/Willyham/following{/other_user}","gists_url":"https://api.github.com/users/Willyham/gists{/gist_id}","starred_url":"https://api.github.com/users/Willyham/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Willyham/subscriptions","organizations_url":"https://api.github.com/users/Willyham/orgs","repos_url":"https://api.github.com/users/Willyham/repos","events_url":"https://api.github.com/users/Willyham/events{/privacy}","received_events_url":"https://api.github.com/users/Willyham/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/pburtchaell/redux-promise-middleware/labels/invalid","name":"invalid","color":"e6e6e6"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":19,"created_at":"2016-04-18T14:17:14Z","updated_at":"2016-04-29T18:59:01Z","closed_at":null,"body":"## Version\r\n3.0.0\r\n## Test Case\r\n```\r\n    it('propagates the original promise', async () => {\r\n      const actionDispatched = store.dispatch({\r\n        type: defaultPromiseAction.type,\r\n        payload: Bluebird.resolve(promiseValue)\r\n      });\r\n\r\n      // Expect that the promise returned has bluebird functions available\r\n      expect(actionDispatched.any).to.be.a('function');\r\n\r\n      await actionDispatched.then(({ value, action }) => {\r\n        expect(value).to.eql(promiseValue);\r\n        expect(action).to.eql(fulfilledAction);\r\n      });\r\n    });\r\n```\r\n## Expected Behavior\r\nThe original promise should be chained and returned.\r\n\r\n## Actual Behavior\r\nA new native promise is created.\r\n\r\n----\r\nI can't see any reason for creating a new promise and rejecting/resolving it. This perpetuates the [deferred anti-pattern](https://github.com/petkaantonov/bluebird/wiki/Promise-anti-patterns#the-deferred-anti-pattern). When changing the code to return the original promise, all of the test suite continues to pass.\r\n\r\nIf there is a reason that a new promise must be created (and that's fine if there is), then the reason is not covered in the tests.\r\n\r\nThe code could be changed to:\r\n\r\n```\r\n      return promise.then(\r\n        (value = null) => {\r\n          const resolvedAction = getAction(value, false);\r\n          dispatch(resolvedAction);\r\n          return { value, action: resolvedAction };\r\n        }).catch((reason = null) => {\r\n          const rejectedAction = getAction(reason, true);\r\n          dispatch(rejectedAction);\r\n          const rejectedDetails = { reason, action: rejectedAction };\r\n          throw rejectedDetails;\r\n        });\r\n```\r\n\r\nto allow any promise library to continue working as expected.\r\n\r\nHappy to submit a PR if this is a valid change."},"comment":{"url":"https://api.github.com/repos/pburtchaell/redux-promise-middleware/issues/comments/215848787","html_url":"https://github.com/pburtchaell/redux-promise-middleware/issues/71#issuecomment-215848787","issue_url":"https://api.github.com/repos/pburtchaell/redux-promise-middleware/issues/71","id":215848787,"user":{"login":"pburtchaell","id":3857324,"avatar_url":"https://avatars.githubusercontent.com/u/3857324?v=3","gravatar_id":"","url":"https://api.github.com/users/pburtchaell","html_url":"https://github.com/pburtchaell","followers_url":"https://api.github.com/users/pburtchaell/followers","following_url":"https://api.github.com/users/pburtchaell/following{/other_user}","gists_url":"https://api.github.com/users/pburtchaell/gists{/gist_id}","starred_url":"https://api.github.com/users/pburtchaell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pburtchaell/subscriptions","organizations_url":"https://api.github.com/users/pburtchaell/orgs","repos_url":"https://api.github.com/users/pburtchaell/repos","events_url":"https://api.github.com/users/pburtchaell/events{/privacy}","received_events_url":"https://api.github.com/users/pburtchaell/received_events","type":"User","site_admin":false},"created_at":"2016-04-29T18:59:01Z","updated_at":"2016-04-29T18:59:01Z","body":"Sorry for my lack of participation in this discussion; I’ve been quite busy. I’ll try to read through everything soon.\n> On Apr 22, 2016, at 9:30 AM, Will Demaine <notifications@github.com> wrote:\n> \n> That last point actually opens up a nice use case for my proposed change. Bluebird emits global unhandledrejection events on window for rejected promises (something supported in Chrome 49 for native promises but as far as I can see, not in other browsers). With the current implementation I wouldn't be able to make use of that event, but if we return the original promise it would work as expected.\n> \n> —\n> You are receiving this because you modified the open/close state.\n> Reply to this email directly or view it on GitHub <https://github.com/pburtchaell/redux-promise-middleware/issues/71#issuecomment-213449626>\n\n"}}