{"action":"created","comment":{"url":"https://api.github.com/repos/JunoLab/Blink.jl/pulls/comments/224817980","pull_request_review_id":164284694,"id":224817980,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIyNDgxNzk4MA==","diff_hunk":"@@ -0,0 +1,202 @@\n+# [Communication between Julia and Javascript](@id Communication)\n+\n+After creating a Window and loading HTML and JS, you may want to interact with\n+julia code (e.g. by clicking a button in HTML, or displaying a plot from julia).\n+\n+This section covers this two-way communication.\n+\n+## Julia to Javascript\n+```@setup Blink-win\n+using Blink\n+win = Window(Dict(:show=>false), async=false)\n+```\n+\n+The easiest way to communicate to javascript from julia is with the [`@js`](@ref) and\n+[`@js_`](@ref) macros. These macros allow you to execute arbitrary javascript code in a\n+given Window.\n+\n+```@repl Blink-win\n+@js win x = 5;\n+@js win x\n+```\n+\n+The `@js_` macro executes its code asynchronously, but doesn't return its\n+result:\n+```@repl Blink-win\n+@time @js win begin   # Blocks until finished; `i` is returned\n+  for i in 0:1000000 end  # waste time\n+  i  # return i\n+end\n+\n+@time @js_ win begin   # Returns immediately, but `i` is not returned.\n+  for i in 0:1000000 end  # waste time\n+  i  # This is ignored\n+end\n+```\n+\n+If your javascript expression is complex, or you want to copy-paste existing\n+javascript, it can be easier to represent it as a pure javascript string.\n+For that, you can call the [`js`](@ref) function with a [`JSString`](@ref Blink.JSString):\n+```@repl Blink-win\n+body!(win, \"\"\"<div id=\"box\" style=\"color:red;\"></div>\"\"\", async=false);\n+div_id = \"box\";\n+js(win, Blink.JSString(\"\"\"document.getElementById(\"$div_id\").style.color\"\"\"))\n+```\n+\n+Note that the code passed to these macros runs in its own scope, so any\n+javascript variables you create with `var` (or the `@var` equivalent for `@js`)\n+will be inaccessible after returning:\n+```@repl Blink-win\n+@js win (@var x_var = 5; x_var)  # x_var is only accessible within this scope.\n+@js win x_var\n+```\n+\n+## Javascript to Julia\n+Communication from javascript to julia currently works via a message passing\n+interface.\n+\n+To invoke julia code from javascript, you specify a julia callback via `handle`:\n+```julia-repl\n+julia> handle(w, \"press\") do args\n+         @show args\n+       end\n+```\n+This callback can then be triggered from javscript via `Blink.msg()`:\n+```@setup handler\n+using Blink\n+w = Window(Dict(:show=>false), async=false)\n+handle(w, \"press\") do args\n+  @show args\n+end\n+```\n+```@repl handler\n+@js w Blink.msg(\"press\", \"Hello from JS\");\n+```\n+Note that `Blink.msg` takes _exactly_ 1 argument.  To pass more or fewer,\n+consider passing an array:\n+```@repl handler\n+@js w Blink.msg(\"press\", [1,2,3]);\n+```\n+(TODO: is this on purpose? Can we fix this to allow variadic args?)","path":"docs/src/communication.md","position":80,"original_position":80,"commit_id":"aa0b4f400f52463a90d1d2598b9faf70ecd7e1ef","original_commit_id":"aa0b4f400f52463a90d1d2598b9faf70ecd7e1ef","user":{"login":"NHDaly","id":1582097,"node_id":"MDQ6VXNlcjE1ODIwOTc=","avatar_url":"https://avatars2.githubusercontent.com/u/1582097?v=4","gravatar_id":"","url":"https://api.github.com/users/NHDaly","html_url":"https://github.com/NHDaly","followers_url":"https://api.github.com/users/NHDaly/followers","following_url":"https://api.github.com/users/NHDaly/following{/other_user}","gists_url":"https://api.github.com/users/NHDaly/gists{/gist_id}","starred_url":"https://api.github.com/users/NHDaly/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NHDaly/subscriptions","organizations_url":"https://api.github.com/users/NHDaly/orgs","repos_url":"https://api.github.com/users/NHDaly/repos","events_url":"https://api.github.com/users/NHDaly/events{/privacy}","received_events_url":"https://api.github.com/users/NHDaly/received_events","type":"User","site_admin":false},"body":"_Is_ this on purpose? Maybe I should start a separate issue about it, but it seems weird that this is the API. Could the javascript function be changed to be variadic? (I actually don't know if you can do that in javascript..)\r\n","created_at":"2018-10-12T15:09:24Z","updated_at":"2018-10-12T15:10:26Z","html_url":"https://github.com/JunoLab/Blink.jl/pull/168#discussion_r224817980","pull_request_url":"https://api.github.com/repos/JunoLab/Blink.jl/pulls/168","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/JunoLab/Blink.jl/pulls/comments/224817980"},"html":{"href":"https://github.com/JunoLab/Blink.jl/pull/168#discussion_r224817980"},"pull_request":{"href":"https://api.github.com/repos/JunoLab/Blink.jl/pulls/168"}}},"pull_request":{"url":"https://api.github.com/repos/JunoLab/Blink.jl/pulls/168","id":222487784,"node_id":"MDExOlB1bGxSZXF1ZXN0MjIyNDg3Nzg0","html_url":"https://github.com/JunoLab/Blink.jl/pull/168","diff_url":"https://github.com/JunoLab/Blink.jl/pull/168.diff","patch_url":"https://github.com/JunoLab/Blink.jl/pull/168.patch","issue_url":"https://api.github.com/repos/JunoLab/Blink.jl/issues/168","number":168,"state":"open","locked":false,"title":"Add a docs/ site for Blink!","user":{"login":"NHDaly","id":1582097,"node_id":"MDQ6VXNlcjE1ODIwOTc=","avatar_url":"https://avatars2.githubusercontent.com/u/1582097?v=4","gravatar_id":"","url":"https://api.github.com/users/NHDaly","html_url":"https://github.com/NHDaly","followers_url":"https://api.github.com/users/NHDaly/followers","following_url":"https://api.github.com/users/NHDaly/following{/other_user}","gists_url":"https://api.github.com/users/NHDaly/gists{/gist_id}","starred_url":"https://api.github.com/users/NHDaly/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NHDaly/subscriptions","organizations_url":"https://api.github.com/users/NHDaly/orgs","repos_url":"https://api.github.com/users/NHDaly/repos","events_url":"https://api.github.com/users/NHDaly/events{/privacy}","received_events_url":"https://api.github.com/users/NHDaly/received_events","type":"User","site_admin":false},"body":"Step 3 of #160: Create a documentation site using [Documenter.jl](https://juliadocs.github.io/Documenter.jl)\r\n\r\nHere is a preview (I think) of what it would look like when we A) merge this in, and B) turn on automatic docs building and deploying through Travis:\r\n\r\nhttps://nhdaly.github.io/Blink.jl/stable/\r\n\r\n\r\nI'd love to talk through this a bit before merging it! :)\r\nAny high-level thoughts about the structure of it, or nit-picky thoughts as well. It's certainly not finished, but I think it's in a good enough state that it's worth putting out there now!\r\n\r\nObviously we haven't finished adding docstrings to all the names in the package, but we can just also add them to the generated `docs/` as we add them! :)\r\n\r\nLet me know what you think!\r\nThanks!","created_at":"2018-10-12T14:35:59Z","updated_at":"2018-10-12T15:10:26Z","closed_at":null,"merged_at":null,"merge_commit_sha":"bd9979511f11b39cd5a0462726e0e7c99e975a17","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/JunoLab/Blink.jl/pulls/168/commits","review_comments_url":"https://api.github.com/repos/JunoLab/Blink.jl/pulls/168/comments","review_comment_url":"https://api.github.com/repos/JunoLab/Blink.jl/pulls/comments{/number}","comments_url":"https://api.github.com/repos/JunoLab/Blink.jl/issues/168/comments","statuses_url":"https://api.github.com/repos/JunoLab/Blink.jl/statuses/aa0b4f400f52463a90d1d2598b9faf70ecd7e1ef","head":{"label":"NHDaly:documenter","ref":"documenter","sha":"aa0b4f400f52463a90d1d2598b9faf70ecd7e1ef","user":{"login":"NHDaly","id":1582097,"node_id":"MDQ6VXNlcjE1ODIwOTc=","avatar_url":"https://avatars2.githubusercontent.com/u/1582097?v=4","gravatar_id":"","url":"https://api.github.com/users/NHDaly","html_url":"https://github.com/NHDaly","followers_url":"https://api.github.com/users/NHDaly/followers","following_url":"https://api.github.com/users/NHDaly/following{/other_user}","gists_url":"https://api.github.com/users/NHDaly/gists{/gist_id}","starred_url":"https://api.github.com/users/NHDaly/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NHDaly/subscriptions","organizations_url":"https://api.github.com/users/NHDaly/orgs","repos_url":"https://api.github.com/users/NHDaly/repos","events_url":"https://api.github.com/users/NHDaly/events{/privacy}","received_events_url":"https://api.github.com/users/NHDaly/received_events","type":"User","site_admin":false},"repo":{"id":115182219,"node_id":"MDEwOlJlcG9zaXRvcnkxMTUxODIyMTk=","name":"Blink.jl","full_name":"NHDaly/Blink.jl","private":false,"owner":{"login":"NHDaly","id":1582097,"node_id":"MDQ6VXNlcjE1ODIwOTc=","avatar_url":"https://avatars2.githubusercontent.com/u/1582097?v=4","gravatar_id":"","url":"https://api.github.com/users/NHDaly","html_url":"https://github.com/NHDaly","followers_url":"https://api.github.com/users/NHDaly/followers","following_url":"https://api.github.com/users/NHDaly/following{/other_user}","gists_url":"https://api.github.com/users/NHDaly/gists{/gist_id}","starred_url":"https://api.github.com/users/NHDaly/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NHDaly/subscriptions","organizations_url":"https://api.github.com/users/NHDaly/orgs","repos_url":"https://api.github.com/users/NHDaly/repos","events_url":"https://api.github.com/users/NHDaly/events{/privacy}","received_events_url":"https://api.github.com/users/NHDaly/received_events","type":"User","site_admin":false},"html_url":"https://github.com/NHDaly/Blink.jl","description":"Web-based GUIs for Julia","fork":true,"url":"https://api.github.com/repos/NHDaly/Blink.jl","forks_url":"https://api.github.com/repos/NHDaly/Blink.jl/forks","keys_url":"https://api.github.com/repos/NHDaly/Blink.jl/keys{/key_id}","collaborators_url":"https://api.github.com/repos/NHDaly/Blink.jl/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/NHDaly/Blink.jl/teams","hooks_url":"https://api.github.com/repos/NHDaly/Blink.jl/hooks","issue_events_url":"https://api.github.com/repos/NHDaly/Blink.jl/issues/events{/number}","events_url":"https://api.github.com/repos/NHDaly/Blink.jl/events","assignees_url":"https://api.github.com/repos/NHDaly/Blink.jl/assignees{/user}","branches_url":"https://api.github.com/repos/NHDaly/Blink.jl/branches{/branch}","tags_url":"https://api.github.com/repos/NHDaly/Blink.jl/tags","blobs_url":"https://api.github.com/repos/NHDaly/Blink.jl/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/NHDaly/Blink.jl/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/NHDaly/Blink.jl/git/refs{/sha}","trees_url":"https://api.github.com/repos/NHDaly/Blink.jl/git/trees{/sha}","statuses_url":"https://api.github.com/repos/NHDaly/Blink.jl/statuses/{sha}","languages_url":"https://api.github.com/repos/NHDaly/Blink.jl/languages","stargazers_url":"https://api.github.com/repos/NHDaly/Blink.jl/stargazers","contributors_url":"https://api.github.com/repos/NHDaly/Blink.jl/contributors","subscribers_url":"https://api.github.com/repos/NHDaly/Blink.jl/subscribers","subscription_url":"https://api.github.com/repos/NHDaly/Blink.jl/subscription","commits_url":"https://api.github.com/repos/NHDaly/Blink.jl/commits{/sha}","git_commits_url":"https://api.github.com/repos/NHDaly/Blink.jl/git/commits{/sha}","comments_url":"https://api.github.com/repos/NHDaly/Blink.jl/comments{/number}","issue_comment_url":"https://api.github.com/repos/NHDaly/Blink.jl/issues/comments{/number}","contents_url":"https://api.github.com/repos/NHDaly/Blink.jl/contents/{+path}","compare_url":"https://api.github.com/repos/NHDaly/Blink.jl/compare/{base}...{head}","merges_url":"https://api.github.com/repos/NHDaly/Blink.jl/merges","archive_url":"https://api.github.com/repos/NHDaly/Blink.jl/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/NHDaly/Blink.jl/downloads","issues_url":"https://api.github.com/repos/NHDaly/Blink.jl/issues{/number}","pulls_url":"https://api.github.com/repos/NHDaly/Blink.jl/pulls{/number}","milestones_url":"https://api.github.com/repos/NHDaly/Blink.jl/milestones{/number}","notifications_url":"https://api.github.com/repos/NHDaly/Blink.jl/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/NHDaly/Blink.jl/labels{/name}","releases_url":"https://api.github.com/repos/NHDaly/Blink.jl/releases{/id}","deployments_url":"https://api.github.com/repos/NHDaly/Blink.jl/deployments","created_at":"2017-12-23T08:28:38Z","updated_at":"2018-10-06T03:16:57Z","pushed_at":"2018-10-12T14:29:25Z","git_url":"git://github.com/NHDaly/Blink.jl.git","ssh_url":"git@github.com:NHDaly/Blink.jl.git","clone_url":"https://github.com/NHDaly/Blink.jl.git","svn_url":"https://github.com/NHDaly/Blink.jl","homepage":"","size":887,"stargazers_count":0,"watchers_count":0,"language":"Julia","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"other","name":"Other","spdx_id":"NOASSERTION","url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"JunoLab:master","ref":"master","sha":"3c54b470bd58349636fc0f3f48f7ef76c4e8991a","user":{"login":"JunoLab","id":8275281,"node_id":"MDEyOk9yZ2FuaXphdGlvbjgyNzUyODE=","avatar_url":"https://avatars2.githubusercontent.com/u/8275281?v=4","gravatar_id":"","url":"https://api.github.com/users/JunoLab","html_url":"https://github.com/JunoLab","followers_url":"https://api.github.com/users/JunoLab/followers","following_url":"https://api.github.com/users/JunoLab/following{/other_user}","gists_url":"https://api.github.com/users/JunoLab/gists{/gist_id}","starred_url":"https://api.github.com/users/JunoLab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JunoLab/subscriptions","organizations_url":"https://api.github.com/users/JunoLab/orgs","repos_url":"https://api.github.com/users/JunoLab/repos","events_url":"https://api.github.com/users/JunoLab/events{/privacy}","received_events_url":"https://api.github.com/users/JunoLab/received_events","type":"Organization","site_admin":false},"repo":{"id":25249448,"node_id":"MDEwOlJlcG9zaXRvcnkyNTI0OTQ0OA==","name":"Blink.jl","full_name":"JunoLab/Blink.jl","private":false,"owner":{"login":"JunoLab","id":8275281,"node_id":"MDEyOk9yZ2FuaXphdGlvbjgyNzUyODE=","avatar_url":"https://avatars2.githubusercontent.com/u/8275281?v=4","gravatar_id":"","url":"https://api.github.com/users/JunoLab","html_url":"https://github.com/JunoLab","followers_url":"https://api.github.com/users/JunoLab/followers","following_url":"https://api.github.com/users/JunoLab/following{/other_user}","gists_url":"https://api.github.com/users/JunoLab/gists{/gist_id}","starred_url":"https://api.github.com/users/JunoLab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JunoLab/subscriptions","organizations_url":"https://api.github.com/users/JunoLab/orgs","repos_url":"https://api.github.com/users/JunoLab/repos","events_url":"https://api.github.com/users/JunoLab/events{/privacy}","received_events_url":"https://api.github.com/users/JunoLab/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/JunoLab/Blink.jl","description":"Web-based GUIs for Julia","fork":false,"url":"https://api.github.com/repos/JunoLab/Blink.jl","forks_url":"https://api.github.com/repos/JunoLab/Blink.jl/forks","keys_url":"https://api.github.com/repos/JunoLab/Blink.jl/keys{/key_id}","collaborators_url":"https://api.github.com/repos/JunoLab/Blink.jl/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/JunoLab/Blink.jl/teams","hooks_url":"https://api.github.com/repos/JunoLab/Blink.jl/hooks","issue_events_url":"https://api.github.com/repos/JunoLab/Blink.jl/issues/events{/number}","events_url":"https://api.github.com/repos/JunoLab/Blink.jl/events","assignees_url":"https://api.github.com/repos/JunoLab/Blink.jl/assignees{/user}","branches_url":"https://api.github.com/repos/JunoLab/Blink.jl/branches{/branch}","tags_url":"https://api.github.com/repos/JunoLab/Blink.jl/tags","blobs_url":"https://api.github.com/repos/JunoLab/Blink.jl/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/JunoLab/Blink.jl/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/JunoLab/Blink.jl/git/refs{/sha}","trees_url":"https://api.github.com/repos/JunoLab/Blink.jl/git/trees{/sha}","statuses_url":"https://api.github.com/repos/JunoLab/Blink.jl/statuses/{sha}","languages_url":"https://api.github.com/repos/JunoLab/Blink.jl/languages","stargazers_url":"https://api.github.com/repos/JunoLab/Blink.jl/stargazers","contributors_url":"https://api.github.com/repos/JunoLab/Blink.jl/contributors","subscribers_url":"https://api.github.com/repos/JunoLab/Blink.jl/subscribers","subscription_url":"https://api.github.com/repos/JunoLab/Blink.jl/subscription","commits_url":"https://api.github.com/repos/JunoLab/Blink.jl/commits{/sha}","git_commits_url":"https://api.github.com/repos/JunoLab/Blink.jl/git/commits{/sha}","comments_url":"https://api.github.com/repos/JunoLab/Blink.jl/comments{/number}","issue_comment_url":"https://api.github.com/repos/JunoLab/Blink.jl/issues/comments{/number}","contents_url":"https://api.github.com/repos/JunoLab/Blink.jl/contents/{+path}","compare_url":"https://api.github.com/repos/JunoLab/Blink.jl/compare/{base}...{head}","merges_url":"https://api.github.com/repos/JunoLab/Blink.jl/merges","archive_url":"https://api.github.com/repos/JunoLab/Blink.jl/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/JunoLab/Blink.jl/downloads","issues_url":"https://api.github.com/repos/JunoLab/Blink.jl/issues{/number}","pulls_url":"https://api.github.com/repos/JunoLab/Blink.jl/pulls{/number}","milestones_url":"https://api.github.com/repos/JunoLab/Blink.jl/milestones{/number}","notifications_url":"https://api.github.com/repos/JunoLab/Blink.jl/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/JunoLab/Blink.jl/labels{/name}","releases_url":"https://api.github.com/repos/JunoLab/Blink.jl/releases{/id}","deployments_url":"https://api.github.com/repos/JunoLab/Blink.jl/deployments","created_at":"2014-10-15T10:14:44Z","updated_at":"2018-10-12T12:41:13Z","pushed_at":"2018-10-12T14:36:00Z","git_url":"git://github.com/JunoLab/Blink.jl.git","ssh_url":"git@github.com:JunoLab/Blink.jl.git","clone_url":"https://github.com/JunoLab/Blink.jl.git","svn_url":"https://github.com/JunoLab/Blink.jl","homepage":"","size":865,"stargazers_count":114,"watchers_count":114,"language":"Julia","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":41,"mirror_url":null,"archived":false,"open_issues_count":25,"license":{"key":"other","name":"Other","spdx_id":"NOASSERTION","url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":41,"open_issues":25,"watchers":114,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/JunoLab/Blink.jl/pulls/168"},"html":{"href":"https://github.com/JunoLab/Blink.jl/pull/168"},"issue":{"href":"https://api.github.com/repos/JunoLab/Blink.jl/issues/168"},"comments":{"href":"https://api.github.com/repos/JunoLab/Blink.jl/issues/168/comments"},"review_comments":{"href":"https://api.github.com/repos/JunoLab/Blink.jl/pulls/168/comments"},"review_comment":{"href":"https://api.github.com/repos/JunoLab/Blink.jl/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/JunoLab/Blink.jl/pulls/168/commits"},"statuses":{"href":"https://api.github.com/repos/JunoLab/Blink.jl/statuses/aa0b4f400f52463a90d1d2598b9faf70ecd7e1ef"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"NHDaly"}}