Skip to content

Instantly share code, notes, and snippets.

@pvdz
Created March 10, 2013 14:07
Show Gist options
  • Select an option

  • Save pvdz/5128700 to your computer and use it in GitHub Desktop.

Select an option

Save pvdz/5128700 to your computer and use it in GitHub Desktop.
requirejs fooky wat Why won't it just work as the example says?
// using requirejs 2.1.5
// see second example after http://requirejs.org/docs/plugins.html#apiload
define({
load: function (name, req, onload, config) {
if (name.slice(0,7) === 'js/user') {
var parse = function(err, source){
if (err) return console.error(err), onload.error(err); // error ajax?
// process source
var par = toTree(source);
translate(par.tok.btree);
source = par.tok.tokens.map(function(t){ return t.value; }).join('');
// now load it. somehow. properly
onload.fromText(source);
//require(['foo'], onload); // would work, but not with `name`... ? also, examples say that's for older r.js version
};
// use local storage is available, otherwise ajax it
var source = localStorage.getItem(name);
if (source) parse(null, source);
else get(name+'.js', parse);
} else {
// let requirejs do it's normal thing
req([name]);
}
}
});
@pvdz
Copy link
Copy Markdown
Author

pvdz commented Mar 10, 2013

Ah, I didn't change the name in define(<name>, ...) before passing it back to requirejs. Seems that was indeed the issue. Thanks for your time! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment