简体   繁体   English

用于协作代码编辑的Ace Editor和meteor:Observe挂起应用程序

[英]Ace Editor and meteor for collaborative code editing: Observe hangs app

I am trying to make a basic collaborative code editor in Meteor using the Ace editor. 我正在尝试使用Ace编辑器在Meteor中创建一个基本的协作代码编辑器。 The javascript is as follows: var file Meteor.startup(function(){ javascript如下:var file Meteor.startup(function(){

        Session.set("file", "fileID");
        var query = Files.find({_id : Session.get("fileId")});

        var handle = query.observe({        
          changed : function(newDoc, oldDoc) {
              if(editor !== undefined){
                console.log("doc was changed from ", oldDoc.contents, "to ",  newDoc.contents);
                editor.setValue(newDoc.contents);
              }
              handle.stop();
            }
        });         

    editor.getSession().on('change', function(e) {
        // update the File collection
        if(Session.get('file')) {
            Files.update({_id: Session.get("file")}, 
              { $set : 
                { 
                  contents : editor.getValue()
                }
              });
        }
    });     

});

The editor is able to update the database without much ado, however, the query that handles observing changes and setting the document to a new value basically just hangs and doesn't do anything. 编辑器能够毫不费力地更新数据库,但是,处理观察更改并将文档设置为新值的查询基本上只会挂起并且不会执行任何操作。 What's the issue? 有什么问题? Or in general what's a better way to solve this problem (of making the ace editor collaborative using meteor...assuming I want to code it myself..and not use meteorite or something) 或者一般来说什么是解决这个问题的更好方法(使用meteor让ace编辑器协同工作......假设我想自己编码......而不是使用陨石或其他东西)

Thanks! 谢谢!

Using the ace editor directly with Meteor will result in laggy operations and clunky interactions between users unless you write and debug a whole lot of code. 除非您编写和调试大量代码,否则直接在Meteor上使用ace编辑器将导致用户之间的延迟操作和笨重的交互。

Another approach is to attach the ShareJS stack to Meteor, because it integrates really well with ace. 另一种方法是将ShareJS堆栈附加到Meteor,因为它与ace集成得非常好。 In fact, I ended up doing this after looking at other ways to do collaborative editing in Meteor: 事实上,在查看了Meteor中进行协作编辑的其他方法之后,我最终做到了这一点:

https://github.com/mizzao/meteor-sharejs https://github.com/mizzao/meteor-sharejs

There is an (out-of-date) demo here: http://documents.meteor.com 这里有一个(过时的)演示: http//documents.meteor.com

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM