Hi guys, working on some browserify issue I found out that some plugins use 
`return` statement to prevent logic from being loaded due to some reason (Api 
is natively supported, we are under Ripple emulation, etc) - see example below. 
This is totally fine since this will be wrapped in function and work correct, 
but this causes browserify issue, (CB-10419 for example). The fix is simple but 
I want to discuss preferred code style - see below - would love to hear what do 
you think. I'm personally prefer Option1 

Issue example

    
https://github.com/apache/cordova-plugin-file/blob/77c63ef181313eba51652e1026cc730fc79ab9f2/www/requestFileSystem.js#L31

    ...

    if (checkBrowser()) {
        return; // THIS CAUSES BROWSERIFY FAILURE
    }

    var argscheck = require('cordova/argscheck'),
        FileError = require('./FileError'),
        FileSystem = require('./FileSystem'),
        exec = require('cordova/exec');
    var fileSystems = require('./fileSystems');

    ...

I see two options to fix this in plugins:

Option1 - wrap module in closure function

    (function() {
    ...
        function checkBrowser() {
            if (cordova.platformId === "browser" && require('./isChrome')()) {
                module.exports = window.requestFileSystem || 
window.webkitRequestFileSystem;
                return true;
            }
            return false;
        }
        if (checkBrowser()) {
            return;
        }
    ...
    })()

Option2 - use if/else
    ...
    if (checkBrowser()) {
        return;
    } else {
        var argscheck = require('cordova/argscheck'),
            FileError = require('./FileError'),
            FileSystem = require('./FileSystem'),
            exec = require('cordova/exec');
        var fileSystems = require('./fileSystems');

    ...
    }

-Sergey

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@cordova.apache.org
For additional commands, e-mail: dev-h...@cordova.apache.org

Reply via email to