I'm messing around with trigger.io's browser extensions framework. It's using addon-sdk when creating .xpi's for Firefox. The tidbit in question is from a main JS file which wraps the API for later use elsewhere by the extension developers. Relevant bit:
var data = require("self").data;
// other stuff
var apiImpl = {
// other APIs here
file: {
string: function (b, c, a) {
c(data.load(b.uri.substring(data.url("").length)))
}
}
}
It looks like data.load()
expects a string like resource://rabblerabble-at-jetpack/f/data/src/a.json
.
What's with the b.uri.substring(data.url("").length))
? What's the point of that?
I had to go digging to figure out why I had to send
forge.file.string({uri:'resource://rabblerabble-at-jetpack/f/data/src/a.json'}, function(data) {
toLog(data);
}, function(e) {toError(e)});
Instead of simply sending the string as the first param.
I have a feeling it's expecting some commonly-used object which you can call a .uri()
on but if that's the case I've no idea what it is.
It looks like
data.load()
expects a string likeresource://rabblerabble-at-jetpack/f/data/src/a.json
.
data.url("")
returns resource://rabblerabble-at-jetpack/f/data/
. So
b.uri.substring(data.url("").length)
returns src/a.json
, which is what data.load()
expects.
The self module has a uri
property. So maybe the forge.file.string()
is structured like that so that it can accept self
as a parameter. That's my best guess without being able to see all the code.