require and reloading modules

3 views
Skip to first unread message

jg

unread,
Nov 19, 2010, 11:43:01 AM11/19/10
to Narwhal and Jack
Hi,

I haven't found any way to reload a module from the shell. I've seen
there are options we can pass to require, but haven't been through it
yet.

Thanks in advance,
Best regards
jg

Kris Kowal

unread,
Nov 19, 2010, 2:33:17 PM11/19/10
to narw...@googlegroups.com
On Fri, Nov 19, 2010 at 8:43 AM, jg <jgra...@gmail.com> wrote:
> I haven't found any way to reload a module from the shell. I've seen
> there are options we can pass to require, but haven't been through it
> yet.

Once you have instantiated a module in a sandbox, all of the modules
in that sandbox have hard references to the instances of their
dependencies, so I don't recommend replacing instantiated modules.
However, Narwhal has a "sandbox" module which will let you instantiate
new sandboxes that can even share a module loader. The module loaders
will reload modules if they've changed.

Take a look at the "sandbox" method in the "sandbox" module. You can
even do clever things where you load your "base set" of modules and
then inherit those whenever you create a new sandbox to speed things
up.

Kris Kowal

Hannes Wallnoefer

unread,
Nov 19, 2010, 4:00:03 PM11/19/10
to Narwhal and Jack
On 19 Nov., 20:33, Kris Kowal <kris.ko...@cixar.com> wrote:
> On Fri, Nov 19, 2010 at 8:43 AM, jg <jgrand...@gmail.com> wrote:
> > I haven't found any way to reload a module from the shell. I've seen
> > there are options we can pass to require, but haven't been through it
> > yet.
>
> Once you have instantiated a module in a sandbox, all of the modules
> in that sandbox have hard references to the instances of their
> dependencies, so I don't recommend replacing instantiated modules.

FYI, Ringo automatically reloads required modules that have changed,
or have direct or transitive dependencies on modules that have
changed, both between shell input lines and HTTP requests. It does so
by a) keeping track of inter-module dependencies and b) avoiding
direct references to module exports from outside the JS runtime (e.g.
an HTTP server). It works well and is quite addictive once you get
used to it.

Hannes

Tom Robinson

unread,
Nov 19, 2010, 5:34:25 PM11/19/10
to narw...@googlegroups.com

Here's an example in Jack: https://github.com/280north/jack/blob/master/lib/jack/reloader.js

It's middleware that automatically reloads all files on every request. Not ideal but it works (unfortunately only in narwhal-rhino, not in narwhal-jsc though)

-tom

Jacques Granduel

unread,
Nov 20, 2010, 8:41:31 AM11/20/10
to narw...@googlegroups.com
Thanks a lot to everybody, I'll give a try to the mentioned solutions.
and long live to narwhal!
Best regards,
jg 

Reply all
Reply to author
Forward
0 new messages