{"action":"created","issue":{"url":"https://api.github.com/repos/vigetlabs/microcosm/issues/64","labels_url":"https://api.github.com/repos/vigetlabs/microcosm/issues/64/labels{/name}","comments_url":"https://api.github.com/repos/vigetlabs/microcosm/issues/64/comments","events_url":"https://api.github.com/repos/vigetlabs/microcosm/issues/64/events","html_url":"https://github.com/vigetlabs/microcosm/pull/64","id":104268124,"number":64,"title":"Stores can have a diversity of registration methods.","user":{"login":"nhunzaker","id":590904,"avatar_url":"https://avatars.githubusercontent.com/u/590904?v=3","gravatar_id":"","url":"https://api.github.com/users/nhunzaker","html_url":"https://github.com/nhunzaker","followers_url":"https://api.github.com/users/nhunzaker/followers","following_url":"https://api.github.com/users/nhunzaker/following{/other_user}","gists_url":"https://api.github.com/users/nhunzaker/gists{/gist_id}","starred_url":"https://api.github.com/users/nhunzaker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nhunzaker/subscriptions","organizations_url":"https://api.github.com/users/nhunzaker/orgs","repos_url":"https://api.github.com/users/nhunzaker/repos","events_url":"https://api.github.com/users/nhunzaker/events{/privacy}","received_events_url":"https://api.github.com/users/nhunzaker/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-09-01T13:35:54Z","updated_at":"2015-09-03T19:31:37Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/vigetlabs/microcosm/pulls/64","html_url":"https://github.com/vigetlabs/microcosm/pull/64","diff_url":"https://github.com/vigetlabs/microcosm/pull/64.diff","patch_url":"https://github.com/vigetlabs/microcosm/pull/64.patch"},"body":"This commit allows the following behaviors:\r\n\r\n```javascript\r\nfunction Store() {\r\n  return {\r\n    [action]: (a,b) => a + b\r\n  }\r\n}\r\n```\r\n\r\n```javascript\r\nfunction Store() {\r\n  return {\r\n    [action]: 10\r\n  }\r\n}\r\n```\r\n\r\nThis is to support some future work on refactoring the store, dispatching process. It also opens up the flexibility for stores to interact with other parts."},"comment":{"url":"https://api.github.com/repos/vigetlabs/microcosm/issues/comments/137550136","html_url":"https://github.com/vigetlabs/microcosm/pull/64#issuecomment-137550136","issue_url":"https://api.github.com/repos/vigetlabs/microcosm/issues/64","id":137550136,"user":{"login":"nhunzaker","id":590904,"avatar_url":"https://avatars.githubusercontent.com/u/590904?v=3","gravatar_id":"","url":"https://api.github.com/users/nhunzaker","html_url":"https://github.com/nhunzaker","followers_url":"https://api.github.com/users/nhunzaker/followers","following_url":"https://api.github.com/users/nhunzaker/following{/other_user}","gists_url":"https://api.github.com/users/nhunzaker/gists{/gist_id}","starred_url":"https://api.github.com/users/nhunzaker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nhunzaker/subscriptions","organizations_url":"https://api.github.com/users/nhunzaker/orgs","repos_url":"https://api.github.com/users/nhunzaker/repos","events_url":"https://api.github.com/users/nhunzaker/events{/privacy}","received_events_url":"https://api.github.com/users/nhunzaker/received_events","type":"User","site_admin":false},"created_at":"2015-09-03T19:31:37Z","updated_at":"2015-09-03T19:31:37Z","body":"@ltk Ooo debate time.\r\n\r\nThe idea was to allow Stores to act like switches that can turn on and off values. For example:\r\n\r\n\r\n```javascript\r\nfunction TrafficLight() {\r\n    return {\r\n        [red]      : 'stop',\r\n        [yellow] : 'caution',\r\n        [green]  : 'go'\r\n    }\r\n}\r\n```\r\n\r\nI see two draw backs to handlers not being functions. One, if a bad reference to a method is given `(this.doesNotExist)`, it'll return undefined. Also, it adds another way to configure them, possibly increasing the learning curve (but not really enough that I'm concerned about it).\r\n\r\nWhat are your feels here?\r\n\r\nAs for allowing Stores to be functions. The big idea is to allow them to be defined one level higher than a private object. Instead, the module itself is the store. So instead of exporting a Store object, you configure the register method as the public interface of the default export:\r\n\r\nConsider a Store as an object:\r\n\r\n```javascript\r\nconst Planets = {\r\n    getInitialState() {\r\n        return []\r\n    },\r\n    register() {\r\n        return {\r\n            [addPlanet]: Planets.add\r\n        }\r\n    },\r\n\r\n    add(planets, props) {\r\n        return planets.concat(props)\r\n    }\r\n}\r\n\r\nexport default Planets\r\n```\r\n\r\nI have a couple of questions here. What value is having an object providing? `add` is a pure function - what value is it adding being a member of Planets?\r\n\r\nWhy build an object in the first place, when we have a similar pattern already given to us via modules? I'm proposing a Store to look like:\r\n\r\n```javascript\r\nfunction getInitialState () {\r\n    return []\r\n}\r\n\r\nfunction add (planets, props) {\r\n    return planets.concat(props)\r\n}\r\n\r\nfunction register() {\r\n    return {\r\n        [addPlanet]: add\r\n    }\r\n}\r\n\r\nexport default { register, getInitialState }\r\n```\r\n\r\nSo this cuts the object, arguable that it's _that_ much better. However there is a step beyond this in my roadmap. I want to drop `serialize`, `deserialize`, and `getInitialState` as \"special\" methods and just make them _lifecycle methods_. So the final form (just like Dragon Ball Z, there is always _another_ final form, but anyway):\r\n\r\n```javascript\r\nimport Microcosm from 'microcosm'\r\n\r\nconst EMPTY = []\r\n\r\nexport function add (planets, props) {\r\n    return planets.concat(props)\r\n}\r\n\r\nexport default function register() {\r\n    return {\r\n        [Microcosm.willStart] : EMPTY,\r\n        [addPlanet]                : add\r\n    }\r\n}\r\n```\r\n\r\nThose are my thoughts anyway. Thoughts?"}}