mirror of
https://github.com/amark/gun.git
synced 2025-06-06 14:16:44 +00:00
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:
parent
a4b64feef0
commit
e7162aa098
16
lib/file.js
16
lib/file.js
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user