{"action":"created","issue":{"url":"https://api.github.com/repos/FormidableLabs/biff/issues/2","labels_url":"https://api.github.com/repos/FormidableLabs/biff/issues/2/labels{/name}","comments_url":"https://api.github.com/repos/FormidableLabs/biff/issues/2/comments","events_url":"https://api.github.com/repos/FormidableLabs/biff/issues/2/events","html_url":"https://github.com/FormidableLabs/biff/pull/2","id":59186814,"number":2,"title":"New Action Syntax Proposal","user":{"login":"kenwheeler","id":286616,"avatar_url":"https://avatars.githubusercontent.com/u/286616?v=3","gravatar_id":"","url":"https://api.github.com/users/kenwheeler","html_url":"https://github.com/kenwheeler","followers_url":"https://api.github.com/users/kenwheeler/followers","following_url":"https://api.github.com/users/kenwheeler/following{/other_user}","gists_url":"https://api.github.com/users/kenwheeler/gists{/gist_id}","starred_url":"https://api.github.com/users/kenwheeler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kenwheeler/subscriptions","organizations_url":"https://api.github.com/users/kenwheeler/orgs","repos_url":"https://api.github.com/users/kenwheeler/repos","events_url":"https://api.github.com/users/kenwheeler/events{/privacy}","received_events_url":"https://api.github.com/users/kenwheeler/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":33,"created_at":"2015-02-27T04:07:51Z","updated_at":"2015-03-02T19:36:43Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/FormidableLabs/biff/pulls/2","html_url":"https://github.com/FormidableLabs/biff/pull/2","diff_url":"https://github.com/FormidableLabs/biff/pull/2.diff","patch_url":"https://github.com/FormidableLabs/biff/pull/2.patch"},"body":"I want to get some feedback on this and foster a little discussion.\r\n\r\nI've been having some conversations around how and where to handle async. Historically in McFly I had either written an API module that would make async calls and then call actions when resolved, or use the promise returned in Action Creators (prior to removing them this week in search of a better solution).\r\n\r\nWe had discussed doing it in the stores, but I'm not sure thats flexible or sustainable enough, particularly if you have an action who's payload is digested in multiple stores.\r\n\r\nI discussed providing the dispatcher within actions, but after discussing this with Per, this would add async logic into components that call those actions, and it really doesn't belong there.\r\n\r\nThis PR is where I ended up, removing the implicit dispatch call, and providing action creators with the dispatch method.\r\n\r\n**Old syntax:**\r\n\r\n```\r\nbiff.createActions({\r\n    actionMethod: function(arg){\r\n        return {\r\n            actionType: 'ACTION_TYPE',\r\n            data: arg\r\n        }\r\n    }\r\n});\r\n```\r\n\r\n**New syntax:**\r\n\r\n```\r\nbiff.createActions({\r\n    actionMethod: function(arg){\r\n        this.dispatch({\r\n            actionType: 'ACTION_TYPE',\r\n            data: arg\r\n        })\r\n    }\r\n});\r\n```\r\nAn async call using the new syntax would look like:\r\n\r\n```\r\nbiff.createActions({\r\n    actionMethod: function(arg){\r\n\r\n        var _this = this;\r\n\r\n        this.dispatch({\r\n          actionType: 'ACTION_STARTED'\r\n        })\r\n\r\n        request\r\n          .get(url)\r\n          .end(function(error, res){\r\n            if(error) {\r\n              _this.dispatch({\r\n                actionType: 'ACTION_ERROR',\r\n                data: error\r\n              })\r\n              return;\r\n            }\r\n            _this.dispatch({\r\n              actionType: 'ACTION_SUCCESS',\r\n              data: res\r\n            })\r\n          })\r\n          \r\n    }\r\n});\r\n```\r\n\r\nLet me know what you guy think. Here are a couple resources to review some of the current flux theory out there right now:\r\n\r\n[React Conf Flux Panel](https://www.youtube.com/watch?v=LTj4O7WJJ98)\r\n\r\n[Async Requests with React & Flux Revisited ](http://www.code-experience.com/async-requests-with-react-js-and-flux-revisited/) \r\n\r\n[Action Creator Async in NuclearMail by Ian Obermiller](https://github.com/ianobermiller/nuclearmail/blob/master/src/js/ThreadActions.js#L39)\r\n\r\ncc: @per-nilsson @eastridge @colinmegill @rgerstenberger @zachhale @paulathevalley "},"comment":{"url":"https://api.github.com/repos/FormidableLabs/biff/issues/comments/76793871","html_url":"https://github.com/FormidableLabs/biff/pull/2#issuecomment-76793871","issue_url":"https://api.github.com/repos/FormidableLabs/biff/issues/2","id":76793871,"user":{"login":"rgerstenberger","id":710017,"avatar_url":"https://avatars.githubusercontent.com/u/710017?v=3","gravatar_id":"","url":"https://api.github.com/users/rgerstenberger","html_url":"https://github.com/rgerstenberger","followers_url":"https://api.github.com/users/rgerstenberger/followers","following_url":"https://api.github.com/users/rgerstenberger/following{/other_user}","gists_url":"https://api.github.com/users/rgerstenberger/gists{/gist_id}","starred_url":"https://api.github.com/users/rgerstenberger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rgerstenberger/subscriptions","organizations_url":"https://api.github.com/users/rgerstenberger/orgs","repos_url":"https://api.github.com/users/rgerstenberger/repos","events_url":"https://api.github.com/users/rgerstenberger/events{/privacy}","received_events_url":"https://api.github.com/users/rgerstenberger/received_events","type":"User","site_admin":false},"created_at":"2015-03-02T19:36:43Z","updated_at":"2015-03-02T19:36:43Z","body":">One suggestion I would have is to add loading and error states a normalized API of the store. \r\n\r\nAgree\r\n\r\n>I think we should not return promises from the action creators and that the components should be fully synchronous.\r\n\r\nagree\r\n\r\n>So from reading the thread and the example it would seem that triggering multiple actions during a network request (success, fail, etc) is what we are settling on?\r\n\r\nDisagree\r\n\r\nTo Ken's point about multiple store's consuming an action, either store update order matters (`waitFor`) or it doesn't. In the `waitFor` case, I think the async should be a store implementation that when it finishes, continues propagating the action to the next store AKA actually waits for the first store.\r\n\r\nUsing multiple actions that are spawned from an original async action seems messy and problematic to me.\r\n\r\n\r\n"}}