{"action":"closed","number":23,"pull_request":{"url":"https://api.github.com/repos/rackt/history/pulls/23","id":42086744,"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","issue_url":"https://api.github.com/repos/rackt/history/issues/23","number":23,"state":"closed","locked":false,"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},"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","created_at":"2015-08-11T02:21:46Z","updated_at":"2015-08-17T16:22:48Z","closed_at":"2015-08-17T16:22:48Z","merged_at":null,"merge_commit_sha":"0d5b35e45e131c2ae304ba57bdcf97cb10591979","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/rackt/history/pulls/23/commits","review_comments_url":"https://api.github.com/repos/rackt/history/pulls/23/comments","review_comment_url":"https://api.github.com/repos/rackt/history/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rackt/history/issues/23/comments","statuses_url":"https://api.github.com/repos/rackt/history/statuses/217f84336bd8a46a87461cecbdfc61c58f2f6414","head":{"label":"aldendaniels:master","ref":"master","sha":"217f84336bd8a46a87461cecbdfc61c58f2f6414","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},"repo":{"id":40515669,"name":"history","full_name":"aldendaniels/history","owner":{"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},"private":false,"html_url":"https://github.com/aldendaniels/history","description":"A minimal, functional history implementation for JavaScript","fork":true,"url":"https://api.github.com/repos/aldendaniels/history","forks_url":"https://api.github.com/repos/aldendaniels/history/forks","keys_url":"https://api.github.com/repos/aldendaniels/history/keys{/key_id}","collaborators_url":"https://api.github.com/repos/aldendaniels/history/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/aldendaniels/history/teams","hooks_url":"https://api.github.com/repos/aldendaniels/history/hooks","issue_events_url":"https://api.github.com/repos/aldendaniels/history/issues/events{/number}","events_url":"https://api.github.com/repos/aldendaniels/history/events","assignees_url":"https://api.github.com/repos/aldendaniels/history/assignees{/user}","branches_url":"https://api.github.com/repos/aldendaniels/history/branches{/branch}","tags_url":"https://api.github.com/repos/aldendaniels/history/tags","blobs_url":"https://api.github.com/repos/aldendaniels/history/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/aldendaniels/history/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/aldendaniels/history/git/refs{/sha}","trees_url":"https://api.github.com/repos/aldendaniels/history/git/trees{/sha}","statuses_url":"https://api.github.com/repos/aldendaniels/history/statuses/{sha}","languages_url":"https://api.github.com/repos/aldendaniels/history/languages","stargazers_url":"https://api.github.com/repos/aldendaniels/history/stargazers","contributors_url":"https://api.github.com/repos/aldendaniels/history/contributors","subscribers_url":"https://api.github.com/repos/aldendaniels/history/subscribers","subscription_url":"https://api.github.com/repos/aldendaniels/history/subscription","commits_url":"https://api.github.com/repos/aldendaniels/history/commits{/sha}","git_commits_url":"https://api.github.com/repos/aldendaniels/history/git/commits{/sha}","comments_url":"https://api.github.com/repos/aldendaniels/history/comments{/number}","issue_comment_url":"https://api.github.com/repos/aldendaniels/history/issues/comments{/number}","contents_url":"https://api.github.com/repos/aldendaniels/history/contents/{+path}","compare_url":"https://api.github.com/repos/aldendaniels/history/compare/{base}...{head}","merges_url":"https://api.github.com/repos/aldendaniels/history/merges","archive_url":"https://api.github.com/repos/aldendaniels/history/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/aldendaniels/history/downloads","issues_url":"https://api.github.com/repos/aldendaniels/history/issues{/number}","pulls_url":"https://api.github.com/repos/aldendaniels/history/pulls{/number}","milestones_url":"https://api.github.com/repos/aldendaniels/history/milestones{/number}","notifications_url":"https://api.github.com/repos/aldendaniels/history/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/aldendaniels/history/labels{/name}","releases_url":"https://api.github.com/repos/aldendaniels/history/releases{/id}","created_at":"2015-08-11T01:56:31Z","updated_at":"2015-08-11T01:56:32Z","pushed_at":"2015-08-11T17:41:18Z","git_url":"git://github.com/aldendaniels/history.git","ssh_url":"git@github.com:aldendaniels/history.git","clone_url":"https://github.com/aldendaniels/history.git","svn_url":"https://github.com/aldendaniels/history","homepage":"","size":410,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"rackt:master","ref":"master","sha":"96cbb9878ab6a778678359f473cd159d8796ac89","user":{"login":"rackt","id":8261421,"avatar_url":"https://avatars.githubusercontent.com/u/8261421?v=3","gravatar_id":"","url":"https://api.github.com/users/rackt","html_url":"https://github.com/rackt","followers_url":"https://api.github.com/users/rackt/followers","following_url":"https://api.github.com/users/rackt/following{/other_user}","gists_url":"https://api.github.com/users/rackt/gists{/gist_id}","starred_url":"https://api.github.com/users/rackt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rackt/subscriptions","organizations_url":"https://api.github.com/users/rackt/orgs","repos_url":"https://api.github.com/users/rackt/repos","events_url":"https://api.github.com/users/rackt/events{/privacy}","received_events_url":"https://api.github.com/users/rackt/received_events","type":"Organization","site_admin":false},"repo":{"id":39316027,"name":"history","full_name":"rackt/history","owner":{"login":"rackt","id":8261421,"avatar_url":"https://avatars.githubusercontent.com/u/8261421?v=3","gravatar_id":"","url":"https://api.github.com/users/rackt","html_url":"https://github.com/rackt","followers_url":"https://api.github.com/users/rackt/followers","following_url":"https://api.github.com/users/rackt/following{/other_user}","gists_url":"https://api.github.com/users/rackt/gists{/gist_id}","starred_url":"https://api.github.com/users/rackt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rackt/subscriptions","organizations_url":"https://api.github.com/users/rackt/orgs","repos_url":"https://api.github.com/users/rackt/repos","events_url":"https://api.github.com/users/rackt/events{/privacy}","received_events_url":"https://api.github.com/users/rackt/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/rackt/history","description":"A minimal, functional history implementation for JavaScript","fork":false,"url":"https://api.github.com/repos/rackt/history","forks_url":"https://api.github.com/repos/rackt/history/forks","keys_url":"https://api.github.com/repos/rackt/history/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rackt/history/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rackt/history/teams","hooks_url":"https://api.github.com/repos/rackt/history/hooks","issue_events_url":"https://api.github.com/repos/rackt/history/issues/events{/number}","events_url":"https://api.github.com/repos/rackt/history/events","assignees_url":"https://api.github.com/repos/rackt/history/assignees{/user}","branches_url":"https://api.github.com/repos/rackt/history/branches{/branch}","tags_url":"https://api.github.com/repos/rackt/history/tags","blobs_url":"https://api.github.com/repos/rackt/history/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rackt/history/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rackt/history/git/refs{/sha}","trees_url":"https://api.github.com/repos/rackt/history/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rackt/history/statuses/{sha}","languages_url":"https://api.github.com/repos/rackt/history/languages","stargazers_url":"https://api.github.com/repos/rackt/history/stargazers","contributors_url":"https://api.github.com/repos/rackt/history/contributors","subscribers_url":"https://api.github.com/repos/rackt/history/subscribers","subscription_url":"https://api.github.com/repos/rackt/history/subscription","commits_url":"https://api.github.com/repos/rackt/history/commits{/sha}","git_commits_url":"https://api.github.com/repos/rackt/history/git/commits{/sha}","comments_url":"https://api.github.com/repos/rackt/history/comments{/number}","issue_comment_url":"https://api.github.com/repos/rackt/history/issues/comments{/number}","contents_url":"https://api.github.com/repos/rackt/history/contents/{+path}","compare_url":"https://api.github.com/repos/rackt/history/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rackt/history/merges","archive_url":"https://api.github.com/repos/rackt/history/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rackt/history/downloads","issues_url":"https://api.github.com/repos/rackt/history/issues{/number}","pulls_url":"https://api.github.com/repos/rackt/history/pulls{/number}","milestones_url":"https://api.github.com/repos/rackt/history/milestones{/number}","notifications_url":"https://api.github.com/repos/rackt/history/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rackt/history/labels{/name}","releases_url":"https://api.github.com/repos/rackt/history/releases{/id}","created_at":"2015-07-18T23:31:47Z","updated_at":"2015-08-17T06:49:49Z","pushed_at":"2015-08-17T16:16:19Z","git_url":"git://github.com/rackt/history.git","ssh_url":"git@github.com:rackt/history.git","clone_url":"https://github.com/rackt/history.git","svn_url":"https://github.com/rackt/history","homepage":"","size":803,"stargazers_count":272,"watchers_count":272,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":12,"mirror_url":null,"open_issues_count":5,"forks":12,"open_issues":5,"watchers":272,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rackt/history/pulls/23"},"html":{"href":"https://github.com/rackt/history/pull/23"},"issue":{"href":"https://api.github.com/repos/rackt/history/issues/23"},"comments":{"href":"https://api.github.com/repos/rackt/history/issues/23/comments"},"review_comments":{"href":"https://api.github.com/repos/rackt/history/pulls/23/comments"},"review_comment":{"href":"https://api.github.com/repos/rackt/history/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rackt/history/pulls/23/commits"},"statuses":{"href":"https://api.github.com/repos/rackt/history/statuses/217f84336bd8a46a87461cecbdfc61c58f2f6414"}},"merged":false,"mergeable":false,"mergeable_state":"dirty","merged_by":null,"comments":4,"review_comments":0,"commits":6,"additions":152,"deletions":13,"changed_files":3}}