require.js with Rhino

Showing 1-3 of 3 messages
require.js with Rhino David Snopek 2/10/10 2:34 AM
Hello!

I am working on a project where some code modules are used both on the
server-side and client-side.  I was previously using my own custom
loader which was reaching its limits, so I decided that even a
requirejs in alpha is more future-looking than trying to improve mine.
;-)

Anyway, the server-side bits are running in Rhino.  In my bootstrap
script I load require.js and then do the following monkey patch:

  require.load = function (moduleName, contextName) {
    var context = require.s.contexts[contextName], url;
    require.s.isDone = false;
    context.loaded[moduleName] = false;

    url = require.nameToUrl(moduleName, null, contextName);
    context.startTime = (new Date()).getTime();
    load(url);

    context.loaded[moduleName] = true;
  };

In my current tests, this appears to work.  That said, the code in
this function was mostly copy-and-pasted from the load() in require.js
plus a couple of glances at build/jslib/requirePatch.js.  I don't know
which parts are un-necessary fluff or if I am missing something
crucial which will become apparent later.

Any advice would be much appreciated!

Thank you,
David Snopek.

Re: require.js with Rhino James Burke 2/10/10 10:15 PM
On Wed, Feb 10, 2010 at 2:34 AM, David Snopek <dsn...@gmail.com> wrote:
> In my current tests, this appears to work.  That said, the code in
> this function was mostly copy-and-pasted from the load() in require.js
> plus a couple of glances at build/jslib/requirePatch.js.  I don't know
> which parts are un-necessary fluff or if I am missing something
> crucial which will become apparent later.
>
> Any advice would be much appreciated!

Great! Thanks for trying it out in Rhino!

I was working on a Rhino adapter, your message motivated me to finish
it, with two simple unit tests:
http://github.com/jrburke/requirejs/commit/96cc08ac4a1066344f4d57726c17be117a7113ef

You can pull the latest from master to get the change. If you look in
the README.md near the bottom there is now a note on Rhino Support.

You had the right solution, although startTime is not really needed
since loading is synchronous, so I did not include it in the
require/rhino.js file. If you see using this code in Rhino in some
async way, that would be interesting to know.

Give a holler if you have any trouble with running the code in Rhino,
I definitely want to support that environment.

James

Re: require.js with Rhino David Snopek 2/11/10 2:31 AM
2010/2/11 James Burke <jrb...@gmail.com>:

> I was working on a Rhino adapter, your message motivated me to finish
> it, with two simple unit tests:
> http://github.com/jrburke/requirejs/commit/96cc08ac4a1066344f4d57726c17be117a7113ef
>
> You can pull the latest from master to get the change. If you look in
> the README.md near the bottom there is now a note on Rhino Support.

Awesome, thanks!  I've updated my bootstrap script to use your
rhino.js and everything continues to work great.

> You had the right solution, although startTime is not really needed
> since loading is synchronous, so I did not include it in the
> require/rhino.js file. If you see using this code in Rhino in some
> async way, that would be interesting to know.

I had a feeling about that, but didn't spend the time to look into
where startTime was actually used.  I don't intend to do any async
loading with Rhino -- at least in this project.  Everything is loaded
when the process starts and then it just rocks out for a while.

> Give a holler if you have any trouble with running the code in Rhino,
> I definitely want to support that environment.

Sure thing!

Thanks again!
David Snopek.