josephg / ShareJS

Collaborative editing in any app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can I use Require.JS to require the client?

ehaughee opened this issue · comments

I am using require.js on the client to load the ace editor but that puts the ace object outside the scope of the <script src="share.js"></script> includes. Is there a way to load sharejs and have it pick up it's dependencies properly?

Its just javascript. Tools like browserify and require.js should work properly on sharejs. IIRC I don't think the ace library is directly referenced by the ace editor bindings, but I could be wrong. Whats the actual problem you're running into?

On the client side I get an error saying 'ace' is not defined inside of share.js/ace.js where it attempts to define the require implementation (requireImpl). But that is what should be happening because I am currently including share.js as a script tag, and including the ace editor with require.js which, of course, scopes the ace object to the inside of the callback function on the require call. So, I am trying to find the best way to include sharejs and its dependencies (ace.js and bcsocket.js) in the same require call.

Good question. Sharejs 0.6?

Yea, 0.6.

I see. So the problem isn't using require.js for sharejs, its that you're trying to mix require.js for ace and not sharejs. ShareJS should work with require, though you might have to wrap a couple of things. Alternately, grab sharejs's ace editor plugin (its just one file) and use require.js for that as well.

From my understanding, the ace.js plugin for share.js allows share.js to interface with ace and its not a replacement for ace. Is this correct? If so, I need the ace editor object (ace) to be in scope before share.js uses its ace.js plugin. Additionally, I have tried including share.js, bcsocket.js, and ace.js in my require statement but I still get ace is not defined errors.

Example code I had for that was something like this:

  require([
    "/bower_components/ace/build/src/ace.js",
    "/vendor/share/bcsocket.js",
    "/vendor/share/share.js",
    "/vendor/share/ace.js"
    ],
    ace) {
      // Here is where I begin to use ace/sharejs
  }

I get the exception here, before reaching the above comment.

Note: I do not have my code attempting to use require.js on that repo/branch yet so it won't match my current environment.