{"action":"created","issue":{"url":"https://api.github.com/repos/davidkpiano/xstate/issues/47","repository_url":"https://api.github.com/repos/davidkpiano/xstate","labels_url":"https://api.github.com/repos/davidkpiano/xstate/issues/47/labels{/name}","comments_url":"https://api.github.com/repos/davidkpiano/xstate/issues/47/comments","events_url":"https://api.github.com/repos/davidkpiano/xstate/issues/47/events","html_url":"https://github.com/davidkpiano/xstate/issues/47","id":290386390,"number":47,"title":"Actions as functions in addition to strings and objects?","user":{"login":"kurtmilam","id":385695,"avatar_url":"https://avatars2.githubusercontent.com/u/385695?v=4","gravatar_id":"","url":"https://api.github.com/users/kurtmilam","html_url":"https://github.com/kurtmilam","followers_url":"https://api.github.com/users/kurtmilam/followers","following_url":"https://api.github.com/users/kurtmilam/following{/other_user}","gists_url":"https://api.github.com/users/kurtmilam/gists{/gist_id}","starred_url":"https://api.github.com/users/kurtmilam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kurtmilam/subscriptions","organizations_url":"https://api.github.com/users/kurtmilam/orgs","repos_url":"https://api.github.com/users/kurtmilam/repos","events_url":"https://api.github.com/users/kurtmilam/events{/privacy}","received_events_url":"https://api.github.com/users/kurtmilam/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/davidkpiano/xstate/milestones/3","html_url":"https://github.com/davidkpiano/xstate/milestone/3","labels_url":"https://api.github.com/repos/davidkpiano/xstate/milestones/3/labels","id":3296330,"number":3,"title":"3.3","description":null,"creator":{"login":"davidkpiano","id":1093738,"avatar_url":"https://avatars2.githubusercontent.com/u/1093738?v=4","gravatar_id":"","url":"https://api.github.com/users/davidkpiano","html_url":"https://github.com/davidkpiano","followers_url":"https://api.github.com/users/davidkpiano/followers","following_url":"https://api.github.com/users/davidkpiano/following{/other_user}","gists_url":"https://api.github.com/users/davidkpiano/gists{/gist_id}","starred_url":"https://api.github.com/users/davidkpiano/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidkpiano/subscriptions","organizations_url":"https://api.github.com/users/davidkpiano/orgs","repos_url":"https://api.github.com/users/davidkpiano/repos","events_url":"https://api.github.com/users/davidkpiano/events{/privacy}","received_events_url":"https://api.github.com/users/davidkpiano/received_events","type":"User","site_admin":false},"open_issues":1,"closed_issues":1,"state":"open","created_at":"2018-04-25T13:06:32Z","updated_at":"2018-05-12T15:09:20Z","due_on":null,"closed_at":null},"comments":2,"created_at":"2018-01-22T08:37:35Z","updated_at":"2018-05-12T15:09:20Z","closed_at":"2018-05-12T15:09:20Z","author_association":"NONE","body":"## Bug or feature request?\r\nFeature Request\r\n\r\n## Description:\r\nSince functions are first-class citizens in JavaScript, and in the interest of reducing boilerplate, I suggest that function actions would be more ergonomic than strings or objects (in many cases).\r\n\r\n## (Feature) Potential implementation:\r\n\r\n- What the API would look like:\r\n\r\nNew Syntax:\r\n```\r\nconst initTimer = seconds => () => {\r\n  // use seconds to initiate a timer\r\n}\r\n\r\nconst machine = Machine({\r\n  initial: '1',\r\n  states: {\r\n    '1': {\r\n      on: { \r\n        timer: '2'\r\n      },\r\n      onEntry: initTimer(30)\r\n    },\r\n    '2': {\r\n      on: { \r\n        timer: '3'\r\n      },\r\n      onEntry: initTimer(45)\r\n    },\r\n    '3': {\r\n      on: { \r\n        timer: '1'\r\n      },\r\n      onEntry: initTimer(60)\r\n    }\r\n  }\r\n})\r\n```\r\n\r\nCurrent Syntax:\r\n```\r\nconst actionMap = {\r\n  initTimer: ({ seconds }) => {\r\n    // use seconds to initiate a timer\r\n  }\r\n}\r\n\r\nconst machine = Machine({\r\n  initial: '1',\r\n  states: {\r\n    '1': {\r\n      on: { \r\n        timer: '2'\r\n      },\r\n      onEntry: { type: 'initTimer', seconds: 30 }\r\n    },\r\n    '2': {\r\n      on: { \r\n        timer: '3'\r\n      },\r\n      onEntry: { type: 'initTimer', seconds: 45 }\r\n    },\r\n    '3': {\r\n      on: { \r\n        timer: '1'\r\n      },\r\n      onEntry: { type: 'initTimer', seconds: 60 }\r\n    }\r\n  }\r\n})\r\n```\r\n- If this is a breaking change\r\nI don't see this as a breaking change. Actions are already polymorphic (either string or object), and it's the user's responsibility to determine what type an action is and what to do with it / how to handle it. In effect, this is likely to be a documentation change plus a ts change to allow actions of type `function`. This would signal to users that actions can be functions and that this construction is specifically supported by project maintainers.\r\n\r\n- If this is part of the existing [SCXML specification](https://www.w3.org/TR/scxml/)\r\nIt's a variation on the definition of actions in the SCXML spec.\r\n"},"comment":{"url":"https://api.github.com/repos/davidkpiano/xstate/issues/comments/388561476","html_url":"https://github.com/davidkpiano/xstate/issues/47#issuecomment-388561476","issue_url":"https://api.github.com/repos/davidkpiano/xstate/issues/47","id":388561476,"user":{"login":"davidkpiano","id":1093738,"avatar_url":"https://avatars2.githubusercontent.com/u/1093738?v=4","gravatar_id":"","url":"https://api.github.com/users/davidkpiano","html_url":"https://github.com/davidkpiano","followers_url":"https://api.github.com/users/davidkpiano/followers","following_url":"https://api.github.com/users/davidkpiano/following{/other_user}","gists_url":"https://api.github.com/users/davidkpiano/gists{/gist_id}","starred_url":"https://api.github.com/users/davidkpiano/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidkpiano/subscriptions","organizations_url":"https://api.github.com/users/davidkpiano/orgs","repos_url":"https://api.github.com/users/davidkpiano/repos","events_url":"https://api.github.com/users/davidkpiano/events{/privacy}","received_events_url":"https://api.github.com/users/davidkpiano/received_events","type":"User","site_admin":false},"created_at":"2018-05-12T15:09:20Z","updated_at":"2018-05-12T15:09:20Z","author_association":"OWNER","body":"Actions as functions will be supported in 3.3, and they're already in `master` 🎉 "}}
{"actor":{"display_login":"davidkpiano"}}