{"action":"created","issue":{"url":"https://api.github.com/repos/BohemianCoding/SketchAPI/issues/240","repository_url":"https://api.github.com/repos/BohemianCoding/SketchAPI","labels_url":"https://api.github.com/repos/BohemianCoding/SketchAPI/issues/240/labels{/name}","comments_url":"https://api.github.com/repos/BohemianCoding/SketchAPI/issues/240/comments","events_url":"https://api.github.com/repos/BohemianCoding/SketchAPI/issues/240/events","html_url":"https://github.com/BohemianCoding/SketchAPI/issues/240","id":346394908,"node_id":"MDU6SXNzdWUzNDYzOTQ5MDg=","number":240,"title":"More intuitive Objective-C method calling API?","user":{"login":"matt-curtis","id":1414704,"node_id":"MDQ6VXNlcjE0MTQ3MDQ=","avatar_url":"https://avatars2.githubusercontent.com/u/1414704?v=4","gravatar_id":"","url":"https://api.github.com/users/matt-curtis","html_url":"https://github.com/matt-curtis","followers_url":"https://api.github.com/users/matt-curtis/followers","following_url":"https://api.github.com/users/matt-curtis/following{/other_user}","gists_url":"https://api.github.com/users/matt-curtis/gists{/gist_id}","starred_url":"https://api.github.com/users/matt-curtis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matt-curtis/subscriptions","organizations_url":"https://api.github.com/users/matt-curtis/orgs","repos_url":"https://api.github.com/users/matt-curtis/repos","events_url":"https://api.github.com/users/matt-curtis/events{/privacy}","received_events_url":"https://api.github.com/users/matt-curtis/received_events","type":"User","site_admin":false},"labels":[{"id":390869717,"node_id":"MDU6TGFiZWwzOTA4Njk3MTc=","url":"https://api.github.com/repos/BohemianCoding/SketchAPI/labels/discussion","name":"discussion","color":"cc317c","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-07-31T23:30:30Z","updated_at":"2018-08-03T00:45:57Z","closed_at":"2018-07-31T23:57:05Z","author_association":"CONTRIBUTOR","body":"I've been doing a fair bit of plugin writing lately, and something that kept bugging me was the existing ways of invoking Objective-C methods - they don't quite integrate well into JavaScript, and throw off linters, syntax highlighters... all which leads me to a possible (better?) alternative to the existing methods of calling method on an Objective-C NSObject class or instance:\r\n\r\nInstead of writing:\r\n\r\n```js\r\nconst window = [[NSPanel alloc]\r\n\tinitWithContentRect: NSMakeRect(0, 0, 420, 646),\r\n\tstyleMask: NSWindowStyleMaskClosable | NSWindowStyleMaskTitled | NSWindowStyleMaskResizable,\r\n\tbacking: NSBackingStoreBuffered,\r\n\tdefer: false\r\n]];\r\n```\r\n\r\nor\r\n\r\n```js\r\nconst window = NSPanel.alloc().initWithContentRect_styleMask_backing_defer(\r\n\tNSMakeRect(0, 0, 420, 646),\r\n\tNSWindowStyleMaskClosable | NSWindowStyleMaskTitled | NSWindowStyleMaskResizable,\r\n\tNSBackingStoreBuffered,\r\n\tfalse\r\n);\r\n```\r\n\r\nWe could instead write:\r\n\r\n```js\r\nconst window = NSPanel.alloc().call({\r\n\tinitWithContentRect: NSMakeRect(0, 0, 420, 646),\r\n\tstyleMask: NSWindowStyleMaskClosable | NSWindowStyleMaskTitled | NSWindowStyleMaskResizable,\r\n\tbacking: NSBackingStoreBuffered,\r\n\tdefer: false\r\n});\r\n```\r\n\r\nThe advantages are:\r\n\r\n1. linting works as expected\r\n2. your syntax highlighter won't bug out\r\n3. the semantics between an argument an its label is preserved\r\n4. more unintuitive/obvious selector to JS translation than the underscore way\r\n5. no need to use a preprocessor\r\n6. 100% js\r\n\r\nThis is possible because JavaScript objects preserve the key order their object literals were declared with. I've written an [example implementation](https://gist.github.com/matt-curtis/2ab31b12554be0c66a5edd495fbe03e7) here, but it has downsides, namely: extending prototype to add `call` for _every single object_ is kind of terrible, and that it might override any existing NSObject method/property with the name `call`. That second one can be easily overcome though by using `$` in it's place or something.\r\n\r\nThoughts?"},"comment":{"url":"https://api.github.com/repos/BohemianCoding/SketchAPI/issues/comments/410110074","html_url":"https://github.com/BohemianCoding/SketchAPI/issues/240#issuecomment-410110074","issue_url":"https://api.github.com/repos/BohemianCoding/SketchAPI/issues/240","id":410110074,"node_id":"MDEyOklzc3VlQ29tbWVudDQxMDExMDA3NA==","user":{"login":"matt-curtis","id":1414704,"node_id":"MDQ6VXNlcjE0MTQ3MDQ=","avatar_url":"https://avatars2.githubusercontent.com/u/1414704?v=4","gravatar_id":"","url":"https://api.github.com/users/matt-curtis","html_url":"https://github.com/matt-curtis","followers_url":"https://api.github.com/users/matt-curtis/followers","following_url":"https://api.github.com/users/matt-curtis/following{/other_user}","gists_url":"https://api.github.com/users/matt-curtis/gists{/gist_id}","starred_url":"https://api.github.com/users/matt-curtis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matt-curtis/subscriptions","organizations_url":"https://api.github.com/users/matt-curtis/orgs","repos_url":"https://api.github.com/users/matt-curtis/repos","events_url":"https://api.github.com/users/matt-curtis/events{/privacy}","received_events_url":"https://api.github.com/users/matt-curtis/received_events","type":"User","site_admin":false},"created_at":"2018-08-03T00:45:57Z","updated_at":"2018-08-03T00:45:57Z","author_association":"CONTRIBUTOR","body":"> On a more high-level picture, we want people to use the obj-c API as little as possible with the end goal to have this JS API covering 99% of the cases :)\r\n\r\nI like this goal the most. Should solve this problem entirely. Thanks for the feedback."}}
{"actor":{"display_login":"matt-curtis"}}