在 Meteor 中设置 ShareJS

Setting up ShareJS in Meteor

我在设置 meteor-share.js 时遇到问题。

基本上我遵循了他们的 README。

{{> sharejsAce docid=docid id="editor"}}

第二个docid是什么?我想这是模板的辅助函数,它包含我要同步的文档的唯一名称?

第一个 docid 是什么?这个关键字是 meteor-share.js?

一旦我将其包含在 html(或模板)中,我需要在 js 端做什么(client/server?)?我应该做些什么来制作模板 (sharejsAce) 以共享文本?

我没有在一个页面中维护多个编辑器,所以我不确定我应该在演示中包括和排除什么。

我想知道这是否只是 API 中的一个错误。当我更改为 codemirror 编辑器时,它就起作用了。错误是说:

Uncaught TypeError: Cannot read property 'range' of undefined

我假设您使用的是 1.2.0 版。如果是这种情况,你需要强制降级到1.1.9版本。

您可以通过 运行 以下命令执行此操作:meteor add mizzao:sharejs-ace@=1.1.9 或通过在 .meteor/versions 文件中手动更改版本:mizzao:sharejs-ace@1.1.9.

GitHub 上阅读有关此问题的更多信息。


What is the second docid here? I guess it's a helper function of the template that contains the unique name of the document that I want to synchronize?

{{> sharejsAce docid=docid id="editor"}}中的docid参数用于指定应该在编辑器中显示的文档。因此,second docid 是辅助函数的名称,它只是 returns 文档的 _id 已被选中:

Template.docItem.events =
  "click a": (e) ->
   e.preventDefault()
   Session.set("document", @_id)


Template.editor.helpers
  docid: -> Session.get("document")

Once I include this in a html (or template), what do I need to do in the js side (client/server?)? Is there anything I should do make the template (sharejsAce) to share text?

如果您想使用 Meteor 集合镜像 ShareJS 数据并使用 ShareJS 用户访问控制,您需要创建一个设置文件,如 demo:

{
  "sharejs": {
    "options": {
      "accounts_auth": {
        "authorize": {
            "collection": "documents",
            "token_validations": {
              "or": {
                "invitedUsers": "is_in_array",
                "userId": "is_equal"
              }
            },
            "apply_on": [
              "read",
              "update",
              "create",
              "delete"
            ]
        },
        "authenticate": {
            "collection": "users",
            "token_validations": {
              "_id": "is_equal"
            }
        }
      }
    }
  }
}