将Kotlin编译为JavaScript(Compile Kotlin to JavaScript)
我已经开始研究Kotlin,我想用它代替TypeScript作为我的前端语言。 都编译为JavaScript,所以我想设置它以便创建一个Kotlin文件,我们称它为
myFile.kt
,然后当我运行编译器时,它会生成一个myFile.js
文件。就像TypeScript如何使用
myFile.ts
并将其编译到myFile.js
。我正在使用最新版本的IntelliJ 15与Kotlin的候选版本1。
我一直在搜索整个互联网的方式来做到这一点,但到目前为止,我发现设置IntelliJ的目的是让Kotlin从你的代码中创建一个JavaScript库到一个JAR文件中。 我也无法获得编译我的项目中的任何
kt
文件(他们以前是js
文件)。我现在想要做什么或者我是否以错误的方式思考这个问题?
I've started looking into Kotlin and I'd like to use it instead of TypeScript for my front end language. Both compile down to JavaScript so I'd like to set it up so that I make a Kotlin file, lets call it
myFile.kt
, then when I run the compiler it makes amyFile.js
file.Just like how TypeScript takes a
myFile.ts
and compiles it to amyFile.js
.I'm using the latest version of IntelliJ 15 with release candidate 1 of Kotlin.
I've been searching all over the internet for the way to do this but so far all I've found is setting up IntelliJ so that Kotlin creates a JavaScript library from your code in a JAR file. I also haven't been able to get that to compile any of the
kt
files in my project (they were previouslyjs
files).Is what I'd like to do currently possible or am I thinking about this in the wrong way?
原文:https://stackoverflow.com/questions/35282237
最满意答案
Facebook的做法非常有趣。
执行此类通知的常见方法是在给定的间隔(可能每隔几秒钟)轮询服务器上的脚本(使用AJAX),以检查是否发生了某些事情。 然而,这可能是网络密集型的,你经常做出无意义的请求,因为没有发生任何事情。
Facebook的方式是使用彗星方法,而不是轮询一个间隔,一旦一个投票完成,它发出另一个。 但是,对服务器上的脚本的每个请求都有非常长的超时,服务器只有在发生事件时才响应该请求。 如果您在Facebook上启动了Firebug的“控制台”选项卡,则可能会发现这一点,请求脚本可能需要几分钟。 这是非常巧妙的,因为这种方法会立即减少请求的数量,以及发送数量的频率。 您现在有一个事件框架可以让服务器“触发”事件。
在这之后,根据这些民意测验返回的实际内容,这是一个JSON响应,似乎是一个事件列表,以及有关它们的信息。 尽管如此,还是有点难看。
在实际的技术方面,AJAX是通往这里的方式,因为您可以控制请求超时等诸多事情。 我建议(Stack overflow cliche here)使用jQuery来做AJAX,它会占用很多交叉可兼容性的问题。 在PHP方面,您可以简单地轮询您的PHP脚本中的事件日志数据库表,只有在发生事件时才返回客户端? 我期望有很多方法可以实现这一点。
实现:
服务器端:
在PHP中似乎有一些彗星库的实现,但是老实说,它真的很简单,这可能就像下面的伪代码一样:
while(!has_event_happened()) { sleep(5); } echo json_encode(get_events());
has_event_happened函数只会检查事件表或某些事件中是否发生过任何事情,然后get_events函数将返回表中新行的列表? 取决于问题的上下文。
不要忘记更改您的PHP最大执行时间,否则会提前超时!
客户端:
看看jQuery插件进行Comet交互:
- 项目主页: http : //plugins.jquery.com/project/Comet
- Google代码: http : //code.google.com/p/jquerycomet/ - 看起来在subversion版本库中有一些示例用法。
也就是说,这个插件似乎增加了一些复杂性,在客户端上真的很简单,也许(和jQuery)一样:
function doPoll() { $.get("events.php", {}, function(result) { $.each(result.events, function(event) { //iterate over the events //do something with your event }); doPoll(); //this effectively causes the poll to run again as //soon as the response comes back }, 'json'); } $(document).ready(function() { $.ajaxSetup({ timeout: 1000*60//set a global AJAX timeout of a minute }); doPoll(); // do the first poll });
整个事情取决于你现有的架构如何组合在一起。
The way Facebook does this is pretty interesting.
A common method of doing such notifications is to poll a script on the server (using AJAX) on a given interval (perhaps every few seconds), to check if something has happened. However, this can be pretty network intensive, and you often make pointless requests, because nothing has happened.
The way Facebook does it is using the comet approach, rather than polling on an interval, as soon as one poll completes, it issues another one. However, each request to the script on the server has an extremely long timeout, and the server only responds to the request once something has happened. You can see this happening if you bring up Firebug's Console tab while on Facebook, with requests to a script possibly taking minutes. It is quite ingenious really, since this method cuts down immediately on both the number of requests, and how often you have to send them. You effectively now have an event framework that allows the server to 'fire' events.
Behind this, in terms of the actual content returned from those polls, it's a JSON response, with what appears to be a list of events, and info about them. It's minified though, so is a bit hard to read.
In terms of the actual technology, AJAX is the way to go here, because you can control request timeouts, and many other things. I'd recommend (Stack overflow cliche here) using jQuery to do the AJAX, it'll take a lot of the cross-compability problems away. In terms of PHP, you could simply poll an event log database table in your PHP script, and only return to the client when something happens? There are, I expect, many ways of implementing this.
Implementing:
Server Side:
There appear to be a few implementations of comet libraries in PHP, but to be honest, it really is very simple, something perhaps like the following pseudocode:
while(!has_event_happened()) { sleep(5); } echo json_encode(get_events());
The has_event_happened function would just check if anything had happened in an events table or something, and then the get_events function would return a list of the new rows in the table? Depends on the context of the problem really.
Don't forget to change your PHP max execution time, otherwise it will timeout early!
Client Side:
Take a look at the jQuery plugin for doing Comet interaction:
- Project homepage: http://plugins.jquery.com/project/Comet
- Google Code: https://code.google.com/archive/p/jquerycomet/ - Appears to have some sort of example usage in the subversion repository.
That said, the plugin seems to add a fair bit of complexity, it really is very simple on the client, perhaps (with jQuery) something like:
function doPoll() { $.get("events.php", {}, function(result) { $.each(result.events, function(event) { //iterate over the events //do something with your event }); doPoll(); //this effectively causes the poll to run again as //soon as the response comes back }, 'json'); } $(document).ready(function() { $.ajaxSetup({ timeout: 1000*60//set a global AJAX timeout of a minute }); doPoll(); // do the first poll });
The whole thing depends a lot on how your existing architecture is put together.
相关问答
更多-
Facebook的做法非常有趣。 执行此类通知的常见方法是在给定的间隔(可能每隔几秒钟)轮询服务器上的脚本(使用AJAX),以检查是否发生了某些事情。 然而,这可能是网络密集型的,你经常做出无意义的请求,因为没有发生任何事情。 Facebook的方式是使用彗星方法,而不是轮询一个间隔,一旦一个投票完成,它发出另一个。 但是,对服务器上的脚本的每个请求都有非常长的超时,服务器只有在发生事件时才响应该请求。 如果您在Facebook上启动了Firebug的“控制台”选项卡,则可能会发现这一点,请求脚本可能需要几 ...
-
MailMessage类正在为正文查找单个字符串。 你可以在这里阅读关于这个类的文档 。 您当前的$Body变量是一个字符串数组。 public MailMessage( string from, string to, string subject, string body ) 将$Body变量转换为单个字符串,方法是将其传递给Out-String如评论中提到的@JosefZ: $EmailBody = $myTable | ConvertTo-Csv -NoTyp ...
-
我有完全相同的问题,我可以通过在https://developers.facebook.com/apps应用程序基本信息的网站部分中输入一个url来解决这个问题,添加一个应用程序域和一个画布url ...我因为这是通知链接的网址,所以怀疑它只能使用画布网址。 希望能帮助到你, 干杯! I have had the exact same problem, I was able to fix this by entering a url in the Website part of https://develo ...
-
Facebook实时更新(Facebook real time update)[2023-03-30]
问题已解决。 我无法从facebook获得POST回调,因为我托管了我的rails app n heroku。 使用Heroku它限制了单个进程,因此我只从Facebook获得GET而不是POST。 Heroku使用单个dyno阻止其他进程。 为了支持我们需要让两个dynos从facebook获得回调。 Problem fixed. I am not able to get POST callback from facebook because i hosted my rails app n heroku. ... -
你应该有一个NodeJS和socket.io ,将它安装在你的服务器上 当有事件时,使用Redis保存变量并将其发送到NodeJs或使用此PHP库,您可以将变量从PHP发送到NodeJS服务器: http : //elephant.io/ NodeJs上的数据处理 返回PHP页面使用Socket.io (client javascript)来捕获此事件并显示给最终用户(使用emit和on ) 您可以使用elephant.io来执行此指令: 将PHP与Socket.io一起使用 或者使用Redis : htt ...
-
使用xmpp的实时通知(real time notifications using xmpp)[2023-08-19]
对于这种情况,Pubsub将是一个合适的解决方案。 它可以从我所看到的内容中处理您的所有要求。 如果您希望用户为每种消息类型订阅的方式不同,则需要为每种事件类型设置一个节点(或者,可以在单个节点上使用过滤器,但我认为多个节点更容易)。 节点所有者可以允许任何人发布到节点,因此这不是问题。 提到了PEP,但如果您想要发布给不在您名单中的用户,则不是正确的解决方案。 如果消息传输的简单行为足够丰富,Pubsub还允许您定义所需的消息内容类型或根本不定义消息。 Pubsub would be an appropr ... -
根据文件 - 目前,只有Facebook.com上的应用才能使用应用通知。 通知仅出现在Facebook.com的桌面版本上。 所以你必须在facebook内有一个画布应用程序来发送通知。 另外,还有其他不同的分享方式,看看这篇文章: 在Android中分享 编辑: 实施/feed API- private void publishStory() { Session session = Session.getActiveSession(); if (session != null){ // Ch ...
-
仅限Facebook,Gmail和Twitter的ACTION_SEND。(ACTION_SEND Facebook, Gmail and Twitter only. Android)[2023-04-11]
您可以在设备上获取已安装应用程序的列表,并检查是否已安装您要查找的应用程序。 然后为用户提供选择他想要分享的应用程序的选项 Listpackages = getPackageManager().getInstalledApplications(PackageManager.GET_META_DATA); for (ApplicationInfo appInfo : packages) { if ("com.facebook.katana".equals(appI ... -
没有任何解决方案可以让Facebook的服务器通过webhooks通知访问您的代码,而无法通过可用的公共IP地址访问您的代码,而该IP地址正在收听Facebook的通知 如果托管代码的机器只有一个私有IP,那么您需要某种具有公共IP的代理来将相关请求转发给该机器 There is no solution that will let Facebook's servers reach your code with webhooks notifications without your code being re ...
-
使用facebook的实时更新API接收实时页面订阅源更新(Receiving real-time Page feed update using facebook's real time update api)[2022-01-22]
使用新的subscribed_apps端点 - 无需将应用程序添加到该页面的页面: https : //developers.facebook.com/docs/graph-api/reference/v2.3/page/subscribed_apps 为了使Realtime Updates正常工作,您需要使用subscribed_apps和订阅端点。 Use the new subscribed_apps endpoint - no need to add the App to a Page for th ...