Reliably check file.js options

The FileJS module can be passed options in two ways, and this commit
ensures they're treated in the right way.
Previously, options passed as .put or .get parameters would be favored
over those used on the chain, even if `file` wasn't specified. Now, the
module will only use the method options if `file` is mentioned, falling
back to the chain options.
This was a mistake on my part with the first PR (#268), I failed to notice notice that edge case.
This commit is contained in:
Jesse Gibson 2016-11-15 13:10:00 -07:00
parent a4b64feef0
commit e7162aa098

View File

@ -7,10 +7,20 @@ var Gun = require('../gun'),
file = {};
function isUsingFileJS (context) {
var gun = context.gun;
var opt = context.opt || gun.Back('opt') || {};
return opt.file !== false;
// Options passed via .get or .put.
var methodOptions = context.opt || {};
// Options set on the gun chain.
var chainOptions = context.gun.Back('opt') || {};
// Favor method options over chain options.
var file = methodOptions.hasOwnProperty('file')
? methodOptions.file
: chainOptions.file;
// Return whether the module is disabled.
return file !== false;
}
// queue writes, adapted from https://github.com/toolness/jsondown/blob/master/jsondown.js