From e7162aa09845fd835c1bf2092b950496217d33fc Mon Sep 17 00:00:00 2001 From: Jesse Gibson Date: Tue, 15 Nov 2016 13:10:00 -0700 Subject: [PATCH] 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. --- lib/file.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/file.js b/lib/file.js index 0ee6a169..36459601 100644 --- a/lib/file.js +++ b/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