{"action":"created","issue":{"url":"https://api.github.com/repos/rackt/history/issues/23","labels_url":"https://api.github.com/repos/rackt/history/issues/23/labels{/name}","comments_url":"https://api.github.com/repos/rackt/history/issues/23/comments","events_url":"https://api.github.com/repos/rackt/history/issues/23/events","html_url":"https://github.com/rackt/history/pull/23","id":100211153,"number":23,"title":"Add transition middleware","user":{"login":"aldendaniels","id":4658558,"avatar_url":"https://avatars.githubusercontent.com/u/4658558?v=3","gravatar_id":"","url":"https://api.github.com/users/aldendaniels","html_url":"https://github.com/aldendaniels","followers_url":"https://api.github.com/users/aldendaniels/followers","following_url":"https://api.github.com/users/aldendaniels/following{/other_user}","gists_url":"https://api.github.com/users/aldendaniels/gists{/gist_id}","starred_url":"https://api.github.com/users/aldendaniels/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aldendaniels/subscriptions","organizations_url":"https://api.github.com/users/aldendaniels/orgs","repos_url":"https://api.github.com/users/aldendaniels/repos","events_url":"https://api.github.com/users/aldendaniels/events{/privacy}","received_events_url":"https://api.github.com/users/aldendaniels/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-08-11T02:21:46Z","updated_at":"2015-08-11T18:41:16Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/rackt/history/pulls/23","html_url":"https://github.com/rackt/history/pull/23","diff_url":"https://github.com/rackt/history/pull/23.diff","patch_url":"https://github.com/rackt/history/pull/23.patch"},"body":"#### Status\r\n_WIP_: Working, but needs more tests. Making PR now to get feedback.\r\n\r\n#### Overview\r\nThis is a PR for the functionality described in #22. This lets users register history middleware that can delay, abort, or redirect transitions programatically. A primary use-case for this is to perform data loading or authentication verification before transitioning to a new route.\r\n\r\nThe new API adds two new methods:\r\n\r\n - `registerTransitionMiddleware()`\r\n - `unregisterTransitionMiddleware()`\r\n\r\n#### Example\r\n```javascript\r\nfunction handler(nextLocation, prevLocation, fnNext) {\r\n  fnNext(); // continue;\r\n  // OR\r\n  fnNext(false); // abort\r\n  // OR\r\n  fnNext(createLocation(...)) // redirect.\r\n}\r\n\r\n// Register middleware.\r\nlet unregister = history.registerTransitionMiddleware(handler);\r\n\r\n// Unregister middleware.\r\nunregister() // OR...\r\nhistory.unregisterTransitionMiddleware(handler); \r\n```\r\n\r\n#### Implementation Details\r\n\r\nThe middleware will be invoked\r\n 1. When the history object is initially created\r\n 2. On every subsequent transition\r\n\r\nBecause transitions can now be async, we no longer assert when a new transition interrupts an existing _pending_ transition. Instead, we just silently ignore the interrupted transition.\r\n\r\n#### Possible Deprecation\r\nMiddleware could replace:\r\n\r\n - the `registerTransitionHook()` method\r\n - the `unregisterTransitionHook()` method\r\n - the `getUserConfirmation` option\r\n\r\nThe functionality to prompt the user can be replaced with:\r\n\r\n```javascript\r\nhistory.registerTransitionMiddleware((ignore1, ignore2, fnNext) => {\r\n  fnNext(confirm('Are you sure?'));\r\n});\r\n```\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/rackt/history/issues/comments/130009812","html_url":"https://github.com/rackt/history/pull/23#issuecomment-130009812","issue_url":"https://api.github.com/repos/rackt/history/issues/23","id":130009812,"user":{"login":"mjackson","id":92839,"avatar_url":"https://avatars.githubusercontent.com/u/92839?v=3","gravatar_id":"","url":"https://api.github.com/users/mjackson","html_url":"https://github.com/mjackson","followers_url":"https://api.github.com/users/mjackson/followers","following_url":"https://api.github.com/users/mjackson/following{/other_user}","gists_url":"https://api.github.com/users/mjackson/gists{/gist_id}","starred_url":"https://api.github.com/users/mjackson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mjackson/subscriptions","organizations_url":"https://api.github.com/users/mjackson/orgs","repos_url":"https://api.github.com/users/mjackson/repos","events_url":"https://api.github.com/users/mjackson/events{/privacy}","received_events_url":"https://api.github.com/users/mjackson/received_events","type":"User","site_admin":false},"created_at":"2015-08-11T18:41:16Z","updated_at":"2015-08-11T18:41:16Z","body":"Hey @aldendaniels! Thanks for submitting this PR. Let's discuss in #22 before moving forward here."}}