Skip to content

Commit

Permalink
Mark loaded files
Browse files Browse the repository at this point in the history
  • Loading branch information
elia committed Jan 18, 2014
1 parent 30cec1f commit dbd2ef2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/opal/sprockets/processor.rb
Expand Up @@ -89,7 +89,7 @@ def evaluate(context, locals, &block)
compiler.compile File.read(path), options.merge(:file => r, :requireable => true)
else
context.require_asset r
''
"Opal.loaded[#{r.inspect}] = true;"
end
end.join("\n")

Expand Down
18 changes: 16 additions & 2 deletions opal/corelib/runtime.js
Expand Up @@ -886,9 +886,23 @@
TypeError._super = Error;

Opal.modules = {};
Opal.loaded = {};
Opal.require = function(name) {
if (Opal.loaded[name]) {
return false;
}

var module;
module = Opal.modules[name] || throw Opal.LoadError.$new("cannot load such file -- "+name);
module(Opal);
if (module = Opal.modules[name]) {
Opal.loaded[name] = true;
module(Opal)
return true
} else {
if (Opal.LoadError) {
throw Opal.LoadError.$new("cannot load such file -- "+name);
} else {
throw("cannot load such file -- "+name);
}
}
}
}).call(this);

0 comments on commit dbd2ef2

Please sign in to comment.