{"action":"created","comment":{"url":"https://api.github.com/repos/cerebral/cerebral-module-router/pulls/comments/51396221","id":51396221,"diff_hunk":"@@ -5,189 +5,87 @@ An opinionated URL change handler for Cerebral\n [![Build status][travis-image]][travis-url]\n [![Test coverage][coveralls-image]][coveralls-url]\n [![bitHound Score][bithound-image]][bithound-url]\n+[![Commitizen friendly][commitizen-image]][commitizen-url]\n+[![Semantic Release][semantic-release-image]][semantic-release-url]\n+[![js-standard-style][standard-image]][standard-url]\n+[![Discord][discord-image]][discord-url]\n \n ### Install\n \n `npm install cerebral-module-router`\n \n-### How to use\n-\n-When you build your Cerebral application you do not have to think about routing at all.\n-You only trigger signals that brings your application into the correct state.\n-Let us imagine an application that can open a messages page, and also open specific messages.\n-\n-```javascript\n-\n-import controller from './controller.js';\n-import homeOpened from './signals/homeOpened';\n-import messagesOpened from './signals/messagesOpened';\n-import messageOpened from './signals/messageOpened';\n-\n-controller.signals({\n-  messagesOpened,\n-  messageOpened\n-);\n-```\n-\n-When we want to open the messages we call the signal:\n-\n-```javascript\n-\n-onMessagesClick() {\n-  this.props.signals.messagesOpened();\n-}\n-```\n-\n-When we want to open a single message we call the signal and pass a payload:\n-\n-```javascript\n-\n-onMessageClick(id) {\n-  this.props.signals.messageOpened({\n-    id: id\n-  });\n-}\n-```\n-\n-The signature of a state change is the signal and the payload passed. We can bind this signature to a route. Lets imagine we have implemented our whole application and it works great, we just need to update the addressbar with a url representing the current state of the application.\n-\n-So let us also add a `homeOpened` signal so that we handle the root url as well.\n-\n-```javascript\n+### Quickstart\n \n+```js\n+import Cerebral from 'cerebral';\n+import Model from 'cerebral-model-baobab'\n import Router from 'cerebral-module-router';\n-import controller from './controller.js';\n-import homeOpened from './signals/homeOpened';\n-import messagesOpened from './signals/messagesOpened';\n-import messageOpened from './signals/messageOpened';\n-\n-controller.signals({\n-  homeOpened,\n-  messagesOpened,\n-  messageOpened\n-);\n+import App from './modules/app';\n \n-controller.modules({\n+controller.addModules({\n+  app: App,\n   router: Router({\n-    '/': 'homeOpened',\n-    '/messages': 'messagesOpened',\n-    '/messages/:id': 'messageOpened'\n+    '/': 'app.homeOpened',\n+    '/messages': 'app.messagesOpened',\n+    '/messages/:id': 'app.messageOpened',\n+    '/*': 'app.notFoundOpened'\n   }, {\n-    mapper: { query: true } // Read about this below\n-  });\n-})\n+    onlyHash: true,            // use only hash part of url for matching\n+    // baseUrl: '/',           // base part, that ignored on route match. detected automatically if `onlyHash` option set to true\n+    // preventAutostart: true, // prevents automatic triggering after `modulesLoaded` event\n+    mapper: { query: true }    // options passed to url-mapper\n+  })\n+);\n ```\n \n-Initial url would be handled automatically during application bootstrap if you are using `cerebral-react` (in container's `componentDidMount` method) or `cerebral-angular` (module's `run` section) packages.\n-Otherwise you should call `trigger` method of exposed service to ensure that initial url is handled.\n-\n-The router checks the url and fires the signal related to the url. The url will be parsed and any payload will be passed on the signal. That means if you go to `example.com/messages/123` it will trigger the `messageOpened` signal with the payload `{id: '123'}`.\n-\n-But if you click a message in the list it will also trigger the `messageOpened` signal with the payload `{id: '456'}` and now the url will also update to `example.com/messages/456`.\n-\n-So it works both ways!\n-\n-The important thing to understand here is that your application does not trigger urls to change its state.\n-It triggers signals. Then you bind a route to a signal to allow a url to trigger the signal as well.\n-\n-That means:\n-\n-```javascript\n-\n-// Going to url\n-\"example.com/messages/456\"\n+### How it works\n \n-// Is exactly the same as\n-this.props.signals.messageOpened({\n-  id: '456'\n-});\n-```\n+Cerebral Router Module is lest invasive router, I believe. \n+You can attach router module to already written cerebral application and it would just work.\n \n-### Diving into the app from a url\n-In the example above, when navigating in the app, you have to go to `/messages` before you can go to `/messages/456`.\n-But when you expose urls you could go directly to `/messages/456`. So how do you handle that?\n+* addressbar update while navigating an app. \n \n-```javascript\n+Router listens `signalTrigger` and `signalStart` events.\n+Addressbar would be updated if signal was bound to route in config.\n+Router uses [url-mapper's](https://github.com/cerebral/url-mapper) `stringify` method to get url to set from given route and signal payload.\n \n-...\n-controller.signals({\n-  messageOpened: [...messagesOpened, ...messageOpened]\n-});\n+* trigger correspondent signal with payload while normal app startup. \n \n-controller.modules({\n-  router: Router({\n-    '/': 'homeOpened',\n-    '/messages': 'messagesOpened',\n-    '/messages/:id': 'messageOpened'\n-  });\n-})\n-```\n+Router listens `modulesLoaded` event and schedules correspondent signal trigger if there was not predefined signal execution (see below).\n+Router uses url-mapper's map method to get matched signal and payload to pass.\n+Matched signal trigger would be delayed until signals started by other modules on `modulesLoaded` event would finish if any.\n \n-With Cerebral you are already used to composing chains and actions together and this is also effective when creating routes.\n-Now you might say, \"I do not want to load my messages every time I open a message!\".\n-There are multiple ways to handle this. It depends on when you want to load the messages.\n-\n-But lets say you want to load them whenever you actually go to `/messages`.\n-Inside your `messagesOpened` signal you can just check if there is an ID on the input.\n-If there is an ID it means you are about to open a message, if not it means you are just opening the messages.\n-\n-### What about queries?\n-With Cerebral you get a very powerful way to use queries.\n-But first we have to make a statement: \"Queries are produced by your application, not by users\".\n-With this perspective we can do some wonderful things. Lets get back to opening our message.\n-Inside the component opening the message we want to pass more than the ID of the message.\n-We want to pass: `{withComments: true}`. So that when we load the message, we load it with comments.\n-\n-```javascript\n-\n-onMessageClick(id) {\n-  this.props.signals.messageOpened({\n-    id: id,\n-    withComments: true\n-  });\n-}\n-```\n+* trigger correspondent on history traversal (back and forward navigation). ","path":"README.md","position":178,"original_position":178,"commit_id":"f5bbf5880e6d848ba4942b915f049afe6ebb6932","original_commit_id":"f5bbf5880e6d848ba4942b915f049afe6ebb6932","user":{"login":"christianalfoni","id":3956929,"avatar_url":"https://avatars.githubusercontent.com/u/3956929?v=3","gravatar_id":"","url":"https://api.github.com/users/christianalfoni","html_url":"https://github.com/christianalfoni","followers_url":"https://api.github.com/users/christianalfoni/followers","following_url":"https://api.github.com/users/christianalfoni/following{/other_user}","gists_url":"https://api.github.com/users/christianalfoni/gists{/gist_id}","starred_url":"https://api.github.com/users/christianalfoni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/christianalfoni/subscriptions","organizations_url":"https://api.github.com/users/christianalfoni/orgs","repos_url":"https://api.github.com/users/christianalfoni/repos","events_url":"https://api.github.com/users/christianalfoni/events{/privacy}","received_events_url":"https://api.github.com/users/christianalfoni/received_events","type":"User","site_admin":false},"body":"Header as above?","created_at":"2016-02-01T09:40:19Z","updated_at":"2016-02-01T09:40:19Z","html_url":"https://github.com/cerebral/cerebral-module-router/pull/71#discussion_r51396221","pull_request_url":"https://api.github.com/repos/cerebral/cerebral-module-router/pulls/71","_links":{"self":{"href":"https://api.github.com/repos/cerebral/cerebral-module-router/pulls/comments/51396221"},"html":{"href":"https://github.com/cerebral/cerebral-module-router/pull/71#discussion_r51396221"},"pull_request":{"href":"https://api.github.com/repos/cerebral/cerebral-module-router/pulls/71"}}},"pull_request":{"url":"https://api.github.com/repos/cerebral/cerebral-module-router/pulls/71","id":57807727,"html_url":"https://github.com/cerebral/cerebral-module-router/pull/71","diff_url":"https://github.com/cerebral/cerebral-module-router/pull/71.diff","patch_url":"https://github.com/cerebral/cerebral-module-router/pull/71.patch","issue_url":"https://api.github.com/repos/cerebral/cerebral-module-router/issues/71","number":71,"state":"open","locked":false,"title":"docs(readme): update readme to latest api","user":{"login":"Guria","id":36270,"avatar_url":"https://avatars.githubusercontent.com/u/36270?v=3","gravatar_id":"","url":"https://api.github.com/users/Guria","html_url":"https://github.com/Guria","followers_url":"https://api.github.com/users/Guria/followers","following_url":"https://api.github.com/users/Guria/following{/other_user}","gists_url":"https://api.github.com/users/Guria/gists{/gist_id}","starred_url":"https://api.github.com/users/Guria/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Guria/subscriptions","organizations_url":"https://api.github.com/users/Guria/orgs","repos_url":"https://api.github.com/users/Guria/repos","events_url":"https://api.github.com/users/Guria/events{/privacy}","received_events_url":"https://api.github.com/users/Guria/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-02-01T08:09:02Z","updated_at":"2016-02-01T09:40:19Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e3911c483b488c55987b1c886aead312da240f78","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/cerebral/cerebral-module-router/pulls/71/commits","review_comments_url":"https://api.github.com/repos/cerebral/cerebral-module-router/pulls/71/comments","review_comment_url":"https://api.github.com/repos/cerebral/cerebral-module-router/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cerebral/cerebral-module-router/issues/71/comments","statuses_url":"https://api.github.com/repos/cerebral/cerebral-module-router/statuses/f5bbf5880e6d848ba4942b915f049afe6ebb6932","head":{"label":"cerebral:docs","ref":"docs","sha":"f5bbf5880e6d848ba4942b915f049afe6ebb6932","user":{"login":"cerebral","id":15994611,"avatar_url":"https://avatars.githubusercontent.com/u/15994611?v=3","gravatar_id":"","url":"https://api.github.com/users/cerebral","html_url":"https://github.com/cerebral","followers_url":"https://api.github.com/users/cerebral/followers","following_url":"https://api.github.com/users/cerebral/following{/other_user}","gists_url":"https://api.github.com/users/cerebral/gists{/gist_id}","starred_url":"https://api.github.com/users/cerebral/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cerebral/subscriptions","organizations_url":"https://api.github.com/users/cerebral/orgs","repos_url":"https://api.github.com/users/cerebral/repos","events_url":"https://api.github.com/users/cerebral/events{/privacy}","received_events_url":"https://api.github.com/users/cerebral/received_events","type":"Organization","site_admin":false},"repo":{"id":41587340,"name":"cerebral-module-router","full_name":"cerebral/cerebral-module-router","owner":{"login":"cerebral","id":15994611,"avatar_url":"https://avatars.githubusercontent.com/u/15994611?v=3","gravatar_id":"","url":"https://api.github.com/users/cerebral","html_url":"https://github.com/cerebral","followers_url":"https://api.github.com/users/cerebral/followers","following_url":"https://api.github.com/users/cerebral/following{/other_user}","gists_url":"https://api.github.com/users/cerebral/gists{/gist_id}","starred_url":"https://api.github.com/users/cerebral/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cerebral/subscriptions","organizations_url":"https://api.github.com/users/cerebral/orgs","repos_url":"https://api.github.com/users/cerebral/repos","events_url":"https://api.github.com/users/cerebral/events{/privacy}","received_events_url":"https://api.github.com/users/cerebral/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cerebral/cerebral-module-router","description":"An opinionated URL change handler for Cerebral","fork":false,"url":"https://api.github.com/repos/cerebral/cerebral-module-router","forks_url":"https://api.github.com/repos/cerebral/cerebral-module-router/forks","keys_url":"https://api.github.com/repos/cerebral/cerebral-module-router/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cerebral/cerebral-module-router/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cerebral/cerebral-module-router/teams","hooks_url":"https://api.github.com/repos/cerebral/cerebral-module-router/hooks","issue_events_url":"https://api.github.com/repos/cerebral/cerebral-module-router/issues/events{/number}","events_url":"https://api.github.com/repos/cerebral/cerebral-module-router/events","assignees_url":"https://api.github.com/repos/cerebral/cerebral-module-router/assignees{/user}","branches_url":"https://api.github.com/repos/cerebral/cerebral-module-router/branches{/branch}","tags_url":"https://api.github.com/repos/cerebral/cerebral-module-router/tags","blobs_url":"https://api.github.com/repos/cerebral/cerebral-module-router/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cerebral/cerebral-module-router/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cerebral/cerebral-module-router/git/refs{/sha}","trees_url":"https://api.github.com/repos/cerebral/cerebral-module-router/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cerebral/cerebral-module-router/statuses/{sha}","languages_url":"https://api.github.com/repos/cerebral/cerebral-module-router/languages","stargazers_url":"https://api.github.com/repos/cerebral/cerebral-module-router/stargazers","contributors_url":"https://api.github.com/repos/cerebral/cerebral-module-router/contributors","subscribers_url":"https://api.github.com/repos/cerebral/cerebral-module-router/subscribers","subscription_url":"https://api.github.com/repos/cerebral/cerebral-module-router/subscription","commits_url":"https://api.github.com/repos/cerebral/cerebral-module-router/commits{/sha}","git_commits_url":"https://api.github.com/repos/cerebral/cerebral-module-router/git/commits{/sha}","comments_url":"https://api.github.com/repos/cerebral/cerebral-module-router/comments{/number}","issue_comment_url":"https://api.github.com/repos/cerebral/cerebral-module-router/issues/comments{/number}","contents_url":"https://api.github.com/repos/cerebral/cerebral-module-router/contents/{+path}","compare_url":"https://api.github.com/repos/cerebral/cerebral-module-router/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cerebral/cerebral-module-router/merges","archive_url":"https://api.github.com/repos/cerebral/cerebral-module-router/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cerebral/cerebral-module-router/downloads","issues_url":"https://api.github.com/repos/cerebral/cerebral-module-router/issues{/number}","pulls_url":"https://api.github.com/repos/cerebral/cerebral-module-router/pulls{/number}","milestones_url":"https://api.github.com/repos/cerebral/cerebral-module-router/milestones{/number}","notifications_url":"https://api.github.com/repos/cerebral/cerebral-module-router/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cerebral/cerebral-module-router/labels{/name}","releases_url":"https://api.github.com/repos/cerebral/cerebral-module-router/releases{/id}","deployments_url":"https://api.github.com/repos/cerebral/cerebral-module-router/deployments","created_at":"2015-08-29T09:10:30Z","updated_at":"2016-02-01T09:24:15Z","pushed_at":"2016-02-01T09:20:39Z","git_url":"git://github.com/cerebral/cerebral-module-router.git","ssh_url":"git@github.com:cerebral/cerebral-module-router.git","clone_url":"https://github.com/cerebral/cerebral-module-router.git","svn_url":"https://github.com/cerebral/cerebral-module-router","homepage":"http://cerebral.github.io/cerebral-module-router/index.html","size":228,"stargazers_count":18,"watchers_count":18,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":2,"mirror_url":null,"open_issues_count":8,"forks":2,"open_issues":8,"watchers":18,"default_branch":"master"}},"base":{"label":"cerebral:master","ref":"master","sha":"30fa30efa771f15e103743413a5e6ce5b812a929","user":{"login":"cerebral","id":15994611,"avatar_url":"https://avatars.githubusercontent.com/u/15994611?v=3","gravatar_id":"","url":"https://api.github.com/users/cerebral","html_url":"https://github.com/cerebral","followers_url":"https://api.github.com/users/cerebral/followers","following_url":"https://api.github.com/users/cerebral/following{/other_user}","gists_url":"https://api.github.com/users/cerebral/gists{/gist_id}","starred_url":"https://api.github.com/users/cerebral/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cerebral/subscriptions","organizations_url":"https://api.github.com/users/cerebral/orgs","repos_url":"https://api.github.com/users/cerebral/repos","events_url":"https://api.github.com/users/cerebral/events{/privacy}","received_events_url":"https://api.github.com/users/cerebral/received_events","type":"Organization","site_admin":false},"repo":{"id":41587340,"name":"cerebral-module-router","full_name":"cerebral/cerebral-module-router","owner":{"login":"cerebral","id":15994611,"avatar_url":"https://avatars.githubusercontent.com/u/15994611?v=3","gravatar_id":"","url":"https://api.github.com/users/cerebral","html_url":"https://github.com/cerebral","followers_url":"https://api.github.com/users/cerebral/followers","following_url":"https://api.github.com/users/cerebral/following{/other_user}","gists_url":"https://api.github.com/users/cerebral/gists{/gist_id}","starred_url":"https://api.github.com/users/cerebral/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cerebral/subscriptions","organizations_url":"https://api.github.com/users/cerebral/orgs","repos_url":"https://api.github.com/users/cerebral/repos","events_url":"https://api.github.com/users/cerebral/events{/privacy}","received_events_url":"https://api.github.com/users/cerebral/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cerebral/cerebral-module-router","description":"An opinionated URL change handler for Cerebral","fork":false,"url":"https://api.github.com/repos/cerebral/cerebral-module-router","forks_url":"https://api.github.com/repos/cerebral/cerebral-module-router/forks","keys_url":"https://api.github.com/repos/cerebral/cerebral-module-router/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cerebral/cerebral-module-router/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cerebral/cerebral-module-router/teams","hooks_url":"https://api.github.com/repos/cerebral/cerebral-module-router/hooks","issue_events_url":"https://api.github.com/repos/cerebral/cerebral-module-router/issues/events{/number}","events_url":"https://api.github.com/repos/cerebral/cerebral-module-router/events","assignees_url":"https://api.github.com/repos/cerebral/cerebral-module-router/assignees{/user}","branches_url":"https://api.github.com/repos/cerebral/cerebral-module-router/branches{/branch}","tags_url":"https://api.github.com/repos/cerebral/cerebral-module-router/tags","blobs_url":"https://api.github.com/repos/cerebral/cerebral-module-router/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cerebral/cerebral-module-router/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cerebral/cerebral-module-router/git/refs{/sha}","trees_url":"https://api.github.com/repos/cerebral/cerebral-module-router/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cerebral/cerebral-module-router/statuses/{sha}","languages_url":"https://api.github.com/repos/cerebral/cerebral-module-router/languages","stargazers_url":"https://api.github.com/repos/cerebral/cerebral-module-router/stargazers","contributors_url":"https://api.github.com/repos/cerebral/cerebral-module-router/contributors","subscribers_url":"https://api.github.com/repos/cerebral/cerebral-module-router/subscribers","subscription_url":"https://api.github.com/repos/cerebral/cerebral-module-router/subscription","commits_url":"https://api.github.com/repos/cerebral/cerebral-module-router/commits{/sha}","git_commits_url":"https://api.github.com/repos/cerebral/cerebral-module-router/git/commits{/sha}","comments_url":"https://api.github.com/repos/cerebral/cerebral-module-router/comments{/number}","issue_comment_url":"https://api.github.com/repos/cerebral/cerebral-module-router/issues/comments{/number}","contents_url":"https://api.github.com/repos/cerebral/cerebral-module-router/contents/{+path}","compare_url":"https://api.github.com/repos/cerebral/cerebral-module-router/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cerebral/cerebral-module-router/merges","archive_url":"https://api.github.com/repos/cerebral/cerebral-module-router/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cerebral/cerebral-module-router/downloads","issues_url":"https://api.github.com/repos/cerebral/cerebral-module-router/issues{/number}","pulls_url":"https://api.github.com/repos/cerebral/cerebral-module-router/pulls{/number}","milestones_url":"https://api.github.com/repos/cerebral/cerebral-module-router/milestones{/number}","notifications_url":"https://api.github.com/repos/cerebral/cerebral-module-router/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cerebral/cerebral-module-router/labels{/name}","releases_url":"https://api.github.com/repos/cerebral/cerebral-module-router/releases{/id}","deployments_url":"https://api.github.com/repos/cerebral/cerebral-module-router/deployments","created_at":"2015-08-29T09:10:30Z","updated_at":"2016-02-01T09:24:15Z","pushed_at":"2016-02-01T09:20:39Z","git_url":"git://github.com/cerebral/cerebral-module-router.git","ssh_url":"git@github.com:cerebral/cerebral-module-router.git","clone_url":"https://github.com/cerebral/cerebral-module-router.git","svn_url":"https://github.com/cerebral/cerebral-module-router","homepage":"http://cerebral.github.io/cerebral-module-router/index.html","size":228,"stargazers_count":18,"watchers_count":18,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":2,"mirror_url":null,"open_issues_count":8,"forks":2,"open_issues":8,"watchers":18,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/cerebral/cerebral-module-router/pulls/71"},"html":{"href":"https://github.com/cerebral/cerebral-module-router/pull/71"},"issue":{"href":"https://api.github.com/repos/cerebral/cerebral-module-router/issues/71"},"comments":{"href":"https://api.github.com/repos/cerebral/cerebral-module-router/issues/71/comments"},"review_comments":{"href":"https://api.github.com/repos/cerebral/cerebral-module-router/pulls/71/comments"},"review_comment":{"href":"https://api.github.com/repos/cerebral/cerebral-module-router/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cerebral/cerebral-module-router/pulls/71/commits"},"statuses":{"href":"https://api.github.com/repos/cerebral/cerebral-module-router/statuses/f5bbf5880e6d848ba4942b915f049afe6ebb6932"}}}}