{"action":"created","issue":{"url":"https://api.github.com/repos/idris-lang/Idris-dev/issues/3192","repository_url":"https://api.github.com/repos/idris-lang/Idris-dev","labels_url":"https://api.github.com/repos/idris-lang/Idris-dev/issues/3192/labels{/name}","comments_url":"https://api.github.com/repos/idris-lang/Idris-dev/issues/3192/comments","events_url":"https://api.github.com/repos/idris-lang/Idris-dev/issues/3192/events","html_url":"https://github.com/idris-lang/Idris-dev/issues/3192","id":157182777,"number":3192,"title":"RFC - Javascript code generation needs a variant for wrapping event callbacks","user":{"login":"colin-adams","id":123895,"avatar_url":"https://avatars.githubusercontent.com/u/123895?v=3","gravatar_id":"","url":"https://api.github.com/users/colin-adams","html_url":"https://github.com/colin-adams","followers_url":"https://api.github.com/users/colin-adams/followers","following_url":"https://api.github.com/users/colin-adams/following{/other_user}","gists_url":"https://api.github.com/users/colin-adams/gists{/gist_id}","starred_url":"https://api.github.com/users/colin-adams/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/colin-adams/subscriptions","organizations_url":"https://api.github.com/users/colin-adams/orgs","repos_url":"https://api.github.com/users/colin-adams/repos","events_url":"https://api.github.com/users/colin-adams/events{/privacy}","received_events_url":"https://api.github.com/users/colin-adams/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/idris-lang/Idris-dev/labels/A-Confirmed","name":"A-Confirmed","color":"fbca04"},{"url":"https://api.github.com/repos/idris-lang/Idris-dev/labels/C-Moderate%20Effort","name":"C-Moderate Effort","color":"006b75"},{"url":"https://api.github.com/repos/idris-lang/Idris-dev/labels/F-Request%20For%20Comment","name":"F-Request For Comment","color":"bebe00"},{"url":"https://api.github.com/repos/idris-lang/Idris-dev/labels/G-ECMAScript%20Backend","name":"G-ECMAScript Backend","color":"bfd4f2"},{"url":"https://api.github.com/repos/idris-lang/Idris-dev/labels/U-Foreign%20Function%20Interface","name":"U-Foreign Function Interface","color":"d4c5f9"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-05-27T11:03:37Z","updated_at":"2016-05-28T06:45:41Z","closed_at":null,"body":"I am trying to add an Idris function as a DOM event callback. Whilst I can successfully add the callback, the function does not get called. Inspection of the generated code shows that it falls into the following pattern:\r\n\r\n```javascript\r\nvar i$ffiWrap = function(fid,oldbase,myoldbase) {\r\n    return function() {\r\n   ...\r\n  return i$ret;\r\n }\r\n}\r\n```\r\n\r\nI was able to get it to work by editing the generated code so that the last 3 lines read:\r\n```javascript\r\n return i$ret;\r\n }\r\n}()\r\n```\r\n\r\nSo I think that this is analagous to the case of storing C callbacks in C structs, for which the %wrapper syntax is provided. And maybe we need an equivalent for JS.\r\nIt may be the case that it is already possible to generate such code, and I am just not aware of how to do it. My existing Idris code looks like this:\r\n\r\n```idris\r\nadd_event_listener : JSRef -> String -> (() -> JS_IO ()) -> JS_IO ()\r\nadd_event_listener target event action = do\r\n  if target == null then\r\n    jscall \"function () {console.log(\\\"No target\\\");}()\" (JS_IO ())\r\n  else\r\n    jscall \"function () {%0.addEventListener(%1,%2);}()\" (JSRef -> String -> (JsFn (() -> JS_IO ()\r\n  )) -> JS_IO ()) target event (MkJsFn action)\r\n\r\n```"},"comment":{"url":"https://api.github.com/repos/idris-lang/Idris-dev/issues/comments/222293601","html_url":"https://github.com/idris-lang/Idris-dev/issues/3192#issuecomment-222293601","issue_url":"https://api.github.com/repos/idris-lang/Idris-dev/issues/3192","id":222293601,"user":{"login":"colin-adams","id":123895,"avatar_url":"https://avatars.githubusercontent.com/u/123895?v=3","gravatar_id":"","url":"https://api.github.com/users/colin-adams","html_url":"https://github.com/colin-adams","followers_url":"https://api.github.com/users/colin-adams/followers","following_url":"https://api.github.com/users/colin-adams/following{/other_user}","gists_url":"https://api.github.com/users/colin-adams/gists{/gist_id}","starred_url":"https://api.github.com/users/colin-adams/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/colin-adams/subscriptions","organizations_url":"https://api.github.com/users/colin-adams/orgs","repos_url":"https://api.github.com/users/colin-adams/repos","events_url":"https://api.github.com/users/colin-adams/events{/privacy}","received_events_url":"https://api.github.com/users/colin-adams/received_events","type":"User","site_admin":false},"created_at":"2016-05-28T06:45:41Z","updated_at":"2016-05-28T06:45:41Z","body":"This proposal won't help.\r\nAlthough adding the () gets the function executed at the correct time, the action I am passing through is actually:\r\n\r\n```idris\r\n(reset socket_di)\r\n```\r\n\r\nwhere socket_di was obtained from calling \r\n```javascript\r\nnew WebSocket (...)\r\n```\r\nThis object is functionally fine in other parts of the code, but when I try to call .send on it (within reset), Javascript raises \"Uncaught TypeError: socket_di.send is not a function\" Inspection of socket_di shows it has lost its prototype. So i$ffiWrap is a dead end for me. (socket_di - the identical object) is functional in other parts of my code."}}
{"actor":{"display_login":"colin-adams"}}