Created
March 10, 2013 14:07
-
-
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?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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]); | |
| } | |
| } | |
| }); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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! :)