{"action":"created","issue":{"url":"https://api.github.com/repos/didierfranc/react-waterfall/issues/63","repository_url":"https://api.github.com/repos/didierfranc/react-waterfall","labels_url":"https://api.github.com/repos/didierfranc/react-waterfall/issues/63/labels{/name}","comments_url":"https://api.github.com/repos/didierfranc/react-waterfall/issues/63/comments","events_url":"https://api.github.com/repos/didierfranc/react-waterfall/issues/63/events","html_url":"https://github.com/didierfranc/react-waterfall/pull/63","id":327902928,"node_id":"MDExOlB1bGxSZXF1ZXN0MTkxNTgzNjcw","number":63,"title":"Fix issue with consecutive updates, removing the option to return a promise in action creators","user":{"login":"elisherer","id":1045347,"node_id":"MDQ6VXNlcjEwNDUzNDc=","avatar_url":"https://avatars0.githubusercontent.com/u/1045347?v=4","gravatar_id":"","url":"https://api.github.com/users/elisherer","html_url":"https://github.com/elisherer","followers_url":"https://api.github.com/users/elisherer/followers","following_url":"https://api.github.com/users/elisherer/following{/other_user}","gists_url":"https://api.github.com/users/elisherer/gists{/gist_id}","starred_url":"https://api.github.com/users/elisherer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elisherer/subscriptions","organizations_url":"https://api.github.com/users/elisherer/orgs","repos_url":"https://api.github.com/users/elisherer/repos","events_url":"https://api.github.com/users/elisherer/events{/privacy}","received_events_url":"https://api.github.com/users/elisherer/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2018-05-30T21:17:53Z","updated_at":"2018-06-04T20:02:21Z","closed_at":null,"author_association":"NONE","pull_request":{"url":"https://api.github.com/repos/didierfranc/react-waterfall/pulls/63","html_url":"https://github.com/didierfranc/react-waterfall/pull/63","diff_url":"https://github.com/didierfranc/react-waterfall/pull/63.diff","patch_url":"https://github.com/didierfranc/react-waterfall/pull/63.patch"},"body":"I Fixed the issue with consecutive action calls #55 \r\n\r\nI **removed** the option to return a `Promise` from action creators.\r\nThis seems unnecessary because you could now always run the action and it will apply on the current state, so running it from a promise created in the code (not in the store actions) would work the same.\r\n\r\nI also added a unit test for it (which failed on the version before my change, see first commit).\r\n\r\n**Point of thought**: Shouldn't we use the middleware as a pipeline to interfere with the action creators, passing them the functional setState and let the middleware decide if and when to pass it to the next middleware (allowing thunks/promise middlewares like in redux). "},"comment":{"url":"https://api.github.com/repos/didierfranc/react-waterfall/issues/comments/394480356","html_url":"https://github.com/didierfranc/react-waterfall/pull/63#issuecomment-394480356","issue_url":"https://api.github.com/repos/didierfranc/react-waterfall/issues/63","id":394480356,"node_id":"MDEyOklzc3VlQ29tbWVudDM5NDQ4MDM1Ng==","user":{"login":"ktunkiewicz","id":5413271,"node_id":"MDQ6VXNlcjU0MTMyNzE=","avatar_url":"https://avatars2.githubusercontent.com/u/5413271?v=4","gravatar_id":"","url":"https://api.github.com/users/ktunkiewicz","html_url":"https://github.com/ktunkiewicz","followers_url":"https://api.github.com/users/ktunkiewicz/followers","following_url":"https://api.github.com/users/ktunkiewicz/following{/other_user}","gists_url":"https://api.github.com/users/ktunkiewicz/gists{/gist_id}","starred_url":"https://api.github.com/users/ktunkiewicz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ktunkiewicz/subscriptions","organizations_url":"https://api.github.com/users/ktunkiewicz/orgs","repos_url":"https://api.github.com/users/ktunkiewicz/repos","events_url":"https://api.github.com/users/ktunkiewicz/events{/privacy}","received_events_url":"https://api.github.com/users/ktunkiewicz/received_events","type":"User","site_admin":false},"created_at":"2018-06-04T20:02:21Z","updated_at":"2018-06-04T20:02:21Z","author_association":"NONE","body":"There's nothing bad in this project being \"more and more\" like redux. I'm actually looking at this project as a lightweight replacement for Redux.\r\n\r\nI'm currently working on creating some lightweight, React based widgets, to make the code at least similar to what we write in our main application where we use React + Redux + a lot lot of other libraries. I use `react-waterfall` in conjunction with `preact` and `preact-promise` which gives me a few kilobytes base which is multiple times smaller footprint than React+Redux+all the boilerplate required.\r\n\r\nWhat i'm missing in 'react-waterfall' library is the ability to asynchronously change state from inside the action \"the redux way\". Or is it possible but \r\n\r\nI imagine something like this would work ideally for use cases I usually encounter:\r\n```\r\nactionsCreators: {\r\n  getQuote: (amount, currency) => (state, store) => {\r\n    store.setState({ isGettingQuote: true, quote: null  });\r\n    api.getQuote({ amount, currency })\r\n      .then((res) => {\r\n        store.setState({ isGettingQuote: false, quote: res.quote });\r\n      })\r\n      .catch((e) => {\r\n        store.setState({ isGettingQuote: false})\r\n        tools.parseApiError(e);\r\n      });\r\n  }\r\n}\r\n```\r\n\r\nIMHO **having the state updated synchronously, and only by returning from an action, is an antipattern**. What this means is that you'll have to write your components like this:\r\n```\r\n<button\r\n  onClick={(e) => {\r\n    this.setLoading(true);\r\n    this.getQuote(this.state.amount, this.state.currency);\r\n    // how do I even check success here??\r\n    this.setLoading(false);\r\n  }}\r\n>getQuote</a>\r\n```\r\n\r\nActions should be the only place where logic happens. The components should only gather some data and call an action.\r\nThen that action must do it's job, and the result of that action should be a change in state - in some time, in some way, not necessarily synchronously (because it may be calling an API, loading some data or doing something else) and the result of an action may be different depends on API response, etc. \r\n\r\nBut for this, action creators must have access to setState."}}
{"actor":{"display_login":"ktunkiewicz"}}