{"action":"created","comment":{"url":"https://api.github.com/repos/palantir/plottable/pulls/comments/24867694","id":24867694,"diff_hunk":"@@ -0,0 +1,67 @@\n+///<reference path=\"../reference.ts\" />\n+\n+module Plottable {\n+export module Dispatcher {\n+  export class KeyEvent {\n+    private static _DISPATCHER_KEY = \"__Plottable_Dispatcher_Key\";\n+    private _connected = false;\n+    private _keydownBroadcaster: Core.Broadcaster<Dispatcher.KeyEvent>;\n+    // private _keyupBroadcaster: Core.Broadcaster<Dispatcher.KeyEvent>;\n+    private _processDownCallback = (e: KeyboardEvent) => this._processKeydown(e);\n+\n+    public static getDispatcher(): Dispatcher.KeyEvent {\n+      var dispatcher: KeyEvent = (<any> document)[KeyEvent._DISPATCHER_KEY];\n+      if (dispatcher == null) {\n+        dispatcher = new KeyEvent();\n+        (<any> document)[KeyEvent._DISPATCHER_KEY] = dispatcher;\n+      }\n+      return dispatcher;\n+    }\n+\n+    constructor() {\n+      this._keydownBroadcaster = new Core.Broadcaster(this);\n+    }\n+\n+    private _connect() {\n+      if (!this._connected) {\n+        document.addEventListener(\"keydown\", this._processDownCallback);\n+        this._connected = true;\n+      }\n+    }\n+\n+    private _disconnect() {\n+      if (this._connected &&\n+          this._keydownBroadcaster.getListenerKeys().length === 0) {\n+        document.removeEventListener(\"keydown\", this._processDownCallback);\n+        this._connected = false;\n+      }\n+    }\n+\n+    /**\n+     * Registers a callback to be called whenever a key is pressed,\n+     * or removes the callback if `null` is passed as the callback.\n+     *\n+     * @param {any} key The registration key associated with the callback.\n+     *                  Registration key uniqueness is determined by deep equality.\n+     * @param {(e: KeyboardEvent) => any} callback A callback that takes the\n+     *                                             keydown KeyboardEvent.\n+     * @return {Dispatcher.KeyEvent} The calling Dispatcher.KeyEvent.\n+     */\n+    public onKeydown(key: any, callback: (e: KeyboardEvent) => any): KeyEvent {\n+      if (callback === null) { // remove listener if callback is null\n+        this._keydownBroadcaster.deregisterListener(key);\n+        this._disconnect();\n+      } else {\n+        this._connect();\n+        this._keydownBroadcaster.registerListener(key,\n+          (d: Dispatcher.KeyEvent, e: KeyboardEvent) => callback(e));\n+      }\n+      return this;\n+    }\n+\n+    private _processKeydown(e: KeyboardEvent) {\n+      this._keydownBroadcaster.broadcast(e);","path":"src/dispatchers/keyEventDispatcher.ts","position":63,"original_position":63,"commit_id":"c658cf2bcedee19c8175a56297607b09e4e5693d","original_commit_id":"c658cf2bcedee19c8175a56297607b09e4e5693d","user":{"login":"jtlan","id":1440449,"avatar_url":"https://avatars.githubusercontent.com/u/1440449?v=3","gravatar_id":"","url":"https://api.github.com/users/jtlan","html_url":"https://github.com/jtlan","followers_url":"https://api.github.com/users/jtlan/followers","following_url":"https://api.github.com/users/jtlan/following{/other_user}","gists_url":"https://api.github.com/users/jtlan/gists{/gist_id}","starred_url":"https://api.github.com/users/jtlan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jtlan/subscriptions","organizations_url":"https://api.github.com/users/jtlan/orgs","repos_url":"https://api.github.com/users/jtlan/repos","events_url":"https://api.github.com/users/jtlan/events{/privacy}","received_events_url":"https://api.github.com/users/jtlan/received_events","type":"User","site_admin":false},"body":"Events have additional information, such as if the CTRL key was pressed, that might be useful. Should `Dispatcher.Mouse` also send the events?","created_at":"2015-02-17T23:57:33Z","updated_at":"2015-02-17T23:57:33Z","html_url":"https://github.com/palantir/plottable/pull/1647#discussion_r24867694","pull_request_url":"https://api.github.com/repos/palantir/plottable/pulls/1647","_links":{"self":{"href":"https://api.github.com/repos/palantir/plottable/pulls/comments/24867694"},"html":{"href":"https://github.com/palantir/plottable/pull/1647#discussion_r24867694"},"pull_request":{"href":"https://api.github.com/repos/palantir/plottable/pulls/1647"}}},"pull_request":{"url":"https://api.github.com/repos/palantir/plottable/pulls/1647","id":29486244,"html_url":"https://github.com/palantir/plottable/pull/1647","diff_url":"https://github.com/palantir/plottable/pull/1647.diff","patch_url":"https://github.com/palantir/plottable/pull/1647.patch","issue_url":"https://api.github.com/repos/palantir/plottable/issues/1647","number":1647,"state":"open","locked":false,"title":"Convert Dispatcher.Key to be global","user":{"login":"jtlan","id":1440449,"avatar_url":"https://avatars.githubusercontent.com/u/1440449?v=3","gravatar_id":"","url":"https://api.github.com/users/jtlan","html_url":"https://github.com/jtlan","followers_url":"https://api.github.com/users/jtlan/followers","following_url":"https://api.github.com/users/jtlan/following{/other_user}","gists_url":"https://api.github.com/users/jtlan/gists{/gist_id}","starred_url":"https://api.github.com/users/jtlan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jtlan/subscriptions","organizations_url":"https://api.github.com/users/jtlan/orgs","repos_url":"https://api.github.com/users/jtlan/repos","events_url":"https://api.github.com/users/jtlan/events{/privacy}","received_events_url":"https://api.github.com/users/jtlan/received_events","type":"User","site_admin":false},"body":"Replaced `Dispatcher.Keypress` with `Dispatcher.KeyEvent`, which registers globally and triggers if a key is pressed anywhere.\r\n\r\n`Interaciton.Key` uses this new `Dispatcher.KeyEvent` in conjunction with `Dispatcher.Mouse` to determine where a key event occurs and trigger callbacks only if the key is pressed while the user is moused over the `Component`.","created_at":"2015-02-17T23:00:31Z","updated_at":"2015-02-17T23:57:33Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9d6da4cefdd10a7c7201c5036c199a7195603b94","assignee":{"login":"jtlan","id":1440449,"avatar_url":"https://avatars.githubusercontent.com/u/1440449?v=3","gravatar_id":"","url":"https://api.github.com/users/jtlan","html_url":"https://github.com/jtlan","followers_url":"https://api.github.com/users/jtlan/followers","following_url":"https://api.github.com/users/jtlan/following{/other_user}","gists_url":"https://api.github.com/users/jtlan/gists{/gist_id}","starred_url":"https://api.github.com/users/jtlan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jtlan/subscriptions","organizations_url":"https://api.github.com/users/jtlan/orgs","repos_url":"https://api.github.com/users/jtlan/repos","events_url":"https://api.github.com/users/jtlan/events{/privacy}","received_events_url":"https://api.github.com/users/jtlan/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/palantir/plottable/pulls/1647/commits","review_comments_url":"https://api.github.com/repos/palantir/plottable/pulls/1647/comments","review_comment_url":"https://api.github.com/repos/palantir/plottable/pulls/comments/{number}","comments_url":"https://api.github.com/repos/palantir/plottable/issues/1647/comments","statuses_url":"https://api.github.com/repos/palantir/plottable/statuses/c658cf2bcedee19c8175a56297607b09e4e5693d","head":{"label":"palantir:global-key","ref":"global-key","sha":"c658cf2bcedee19c8175a56297607b09e4e5693d","user":{"login":"palantir","id":303157,"avatar_url":"https://avatars.githubusercontent.com/u/303157?v=3","gravatar_id":"","url":"https://api.github.com/users/palantir","html_url":"https://github.com/palantir","followers_url":"https://api.github.com/users/palantir/followers","following_url":"https://api.github.com/users/palantir/following{/other_user}","gists_url":"https://api.github.com/users/palantir/gists{/gist_id}","starred_url":"https://api.github.com/users/palantir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/palantir/subscriptions","organizations_url":"https://api.github.com/users/palantir/orgs","repos_url":"https://api.github.com/users/palantir/repos","events_url":"https://api.github.com/users/palantir/events{/privacy}","received_events_url":"https://api.github.com/users/palantir/received_events","type":"Organization","site_admin":false},"repo":{"id":16149854,"name":"plottable","full_name":"palantir/plottable","owner":{"login":"palantir","id":303157,"avatar_url":"https://avatars.githubusercontent.com/u/303157?v=3","gravatar_id":"","url":"https://api.github.com/users/palantir","html_url":"https://github.com/palantir","followers_url":"https://api.github.com/users/palantir/followers","following_url":"https://api.github.com/users/palantir/following{/other_user}","gists_url":"https://api.github.com/users/palantir/gists{/gist_id}","starred_url":"https://api.github.com/users/palantir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/palantir/subscriptions","organizations_url":"https://api.github.com/users/palantir/orgs","repos_url":"https://api.github.com/users/palantir/repos","events_url":"https://api.github.com/users/palantir/events{/privacy}","received_events_url":"https://api.github.com/users/palantir/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/palantir/plottable","description":"A library of modular chart components, built on D3","fork":false,"url":"https://api.github.com/repos/palantir/plottable","forks_url":"https://api.github.com/repos/palantir/plottable/forks","keys_url":"https://api.github.com/repos/palantir/plottable/keys{/key_id}","collaborators_url":"https://api.github.com/repos/palantir/plottable/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/palantir/plottable/teams","hooks_url":"https://api.github.com/repos/palantir/plottable/hooks","issue_events_url":"https://api.github.com/repos/palantir/plottable/issues/events{/number}","events_url":"https://api.github.com/repos/palantir/plottable/events","assignees_url":"https://api.github.com/repos/palantir/plottable/assignees{/user}","branches_url":"https://api.github.com/repos/palantir/plottable/branches{/branch}","tags_url":"https://api.github.com/repos/palantir/plottable/tags","blobs_url":"https://api.github.com/repos/palantir/plottable/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/palantir/plottable/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/palantir/plottable/git/refs{/sha}","trees_url":"https://api.github.com/repos/palantir/plottable/git/trees{/sha}","statuses_url":"https://api.github.com/repos/palantir/plottable/statuses/{sha}","languages_url":"https://api.github.com/repos/palantir/plottable/languages","stargazers_url":"https://api.github.com/repos/palantir/plottable/stargazers","contributors_url":"https://api.github.com/repos/palantir/plottable/contributors","subscribers_url":"https://api.github.com/repos/palantir/plottable/subscribers","subscription_url":"https://api.github.com/repos/palantir/plottable/subscription","commits_url":"https://api.github.com/repos/palantir/plottable/commits{/sha}","git_commits_url":"https://api.github.com/repos/palantir/plottable/git/commits{/sha}","comments_url":"https://api.github.com/repos/palantir/plottable/comments{/number}","issue_comment_url":"https://api.github.com/repos/palantir/plottable/issues/comments/{number}","contents_url":"https://api.github.com/repos/palantir/plottable/contents/{+path}","compare_url":"https://api.github.com/repos/palantir/plottable/compare/{base}...{head}","merges_url":"https://api.github.com/repos/palantir/plottable/merges","archive_url":"https://api.github.com/repos/palantir/plottable/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/palantir/plottable/downloads","issues_url":"https://api.github.com/repos/palantir/plottable/issues{/number}","pulls_url":"https://api.github.com/repos/palantir/plottable/pulls{/number}","milestones_url":"https://api.github.com/repos/palantir/plottable/milestones{/number}","notifications_url":"https://api.github.com/repos/palantir/plottable/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/palantir/plottable/labels{/name}","releases_url":"https://api.github.com/repos/palantir/plottable/releases{/id}","created_at":"2014-01-22T19:29:19Z","updated_at":"2015-02-17T21:47:00Z","pushed_at":"2015-02-17T22:58:59Z","git_url":"git://github.com/palantir/plottable.git","ssh_url":"git@github.com:palantir/plottable.git","clone_url":"https://github.com/palantir/plottable.git","svn_url":"https://github.com/palantir/plottable","homepage":"plottablejs.org","size":56666,"stargazers_count":391,"watchers_count":391,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":31,"mirror_url":null,"open_issues_count":143,"forks":31,"open_issues":143,"watchers":391,"default_branch":"develop"}},"base":{"label":"palantir:dispatchers","ref":"dispatchers","sha":"ec8831739d565498d3ff4b661b95111da6b797ca","user":{"login":"palantir","id":303157,"avatar_url":"https://avatars.githubusercontent.com/u/303157?v=3","gravatar_id":"","url":"https://api.github.com/users/palantir","html_url":"https://github.com/palantir","followers_url":"https://api.github.com/users/palantir/followers","following_url":"https://api.github.com/users/palantir/following{/other_user}","gists_url":"https://api.github.com/users/palantir/gists{/gist_id}","starred_url":"https://api.github.com/users/palantir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/palantir/subscriptions","organizations_url":"https://api.github.com/users/palantir/orgs","repos_url":"https://api.github.com/users/palantir/repos","events_url":"https://api.github.com/users/palantir/events{/privacy}","received_events_url":"https://api.github.com/users/palantir/received_events","type":"Organization","site_admin":false},"repo":{"id":16149854,"name":"plottable","full_name":"palantir/plottable","owner":{"login":"palantir","id":303157,"avatar_url":"https://avatars.githubusercontent.com/u/303157?v=3","gravatar_id":"","url":"https://api.github.com/users/palantir","html_url":"https://github.com/palantir","followers_url":"https://api.github.com/users/palantir/followers","following_url":"https://api.github.com/users/palantir/following{/other_user}","gists_url":"https://api.github.com/users/palantir/gists{/gist_id}","starred_url":"https://api.github.com/users/palantir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/palantir/subscriptions","organizations_url":"https://api.github.com/users/palantir/orgs","repos_url":"https://api.github.com/users/palantir/repos","events_url":"https://api.github.com/users/palantir/events{/privacy}","received_events_url":"https://api.github.com/users/palantir/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/palantir/plottable","description":"A library of modular chart components, built on D3","fork":false,"url":"https://api.github.com/repos/palantir/plottable","forks_url":"https://api.github.com/repos/palantir/plottable/forks","keys_url":"https://api.github.com/repos/palantir/plottable/keys{/key_id}","collaborators_url":"https://api.github.com/repos/palantir/plottable/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/palantir/plottable/teams","hooks_url":"https://api.github.com/repos/palantir/plottable/hooks","issue_events_url":"https://api.github.com/repos/palantir/plottable/issues/events{/number}","events_url":"https://api.github.com/repos/palantir/plottable/events","assignees_url":"https://api.github.com/repos/palantir/plottable/assignees{/user}","branches_url":"https://api.github.com/repos/palantir/plottable/branches{/branch}","tags_url":"https://api.github.com/repos/palantir/plottable/tags","blobs_url":"https://api.github.com/repos/palantir/plottable/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/palantir/plottable/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/palantir/plottable/git/refs{/sha}","trees_url":"https://api.github.com/repos/palantir/plottable/git/trees{/sha}","statuses_url":"https://api.github.com/repos/palantir/plottable/statuses/{sha}","languages_url":"https://api.github.com/repos/palantir/plottable/languages","stargazers_url":"https://api.github.com/repos/palantir/plottable/stargazers","contributors_url":"https://api.github.com/repos/palantir/plottable/contributors","subscribers_url":"https://api.github.com/repos/palantir/plottable/subscribers","subscription_url":"https://api.github.com/repos/palantir/plottable/subscription","commits_url":"https://api.github.com/repos/palantir/plottable/commits{/sha}","git_commits_url":"https://api.github.com/repos/palantir/plottable/git/commits{/sha}","comments_url":"https://api.github.com/repos/palantir/plottable/comments{/number}","issue_comment_url":"https://api.github.com/repos/palantir/plottable/issues/comments/{number}","contents_url":"https://api.github.com/repos/palantir/plottable/contents/{+path}","compare_url":"https://api.github.com/repos/palantir/plottable/compare/{base}...{head}","merges_url":"https://api.github.com/repos/palantir/plottable/merges","archive_url":"https://api.github.com/repos/palantir/plottable/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/palantir/plottable/downloads","issues_url":"https://api.github.com/repos/palantir/plottable/issues{/number}","pulls_url":"https://api.github.com/repos/palantir/plottable/pulls{/number}","milestones_url":"https://api.github.com/repos/palantir/plottable/milestones{/number}","notifications_url":"https://api.github.com/repos/palantir/plottable/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/palantir/plottable/labels{/name}","releases_url":"https://api.github.com/repos/palantir/plottable/releases{/id}","created_at":"2014-01-22T19:29:19Z","updated_at":"2015-02-17T21:47:00Z","pushed_at":"2015-02-17T22:58:59Z","git_url":"git://github.com/palantir/plottable.git","ssh_url":"git@github.com:palantir/plottable.git","clone_url":"https://github.com/palantir/plottable.git","svn_url":"https://github.com/palantir/plottable","homepage":"plottablejs.org","size":56666,"stargazers_count":391,"watchers_count":391,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":31,"mirror_url":null,"open_issues_count":143,"forks":31,"open_issues":143,"watchers":391,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/palantir/plottable/pulls/1647"},"html":{"href":"https://github.com/palantir/plottable/pull/1647"},"issue":{"href":"https://api.github.com/repos/palantir/plottable/issues/1647"},"comments":{"href":"https://api.github.com/repos/palantir/plottable/issues/1647/comments"},"review_comments":{"href":"https://api.github.com/repos/palantir/plottable/pulls/1647/comments"},"review_comment":{"href":"https://api.github.com/repos/palantir/plottable/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/palantir/plottable/pulls/1647/commits"},"statuses":{"href":"https://api.github.com/repos/palantir/plottable/statuses/c658cf2bcedee19c8175a56297607b09e4e5693d"}}}}