Created
March 25, 2015 10:24
-
-
Save josephfinlayson/cd1e4a50909935a2b827 to your computer and use it in GitHub Desktop.
Welcome to the function factory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// private: create methods for each config to get/set | |
function createConfig(configObj, providerObj, platformPath) { | |
forEach(configObj, function(value, namespace) { | |
if (angular.isObject(configObj[namespace])) { | |
// recursively drill down the config object so we can create a method for each one | |
providerObj[namespace] = {}; | |
createConfig(configObj[namespace], providerObj[namespace], platformPath + '.' + namespace); | |
} else { | |
// create a method for the provider/config methods that will be exposed | |
providerObj[namespace] = function(newValue) { | |
if (arguments.length) { | |
configObj[namespace] = newValue; | |
return providerObj; | |
} | |
if (configObj[namespace] == PLATFORM) { | |
// if the config is set to 'platform', then get this config's platform value | |
var platformConfig = stringObj(configProperties.platform, ionic.Platform.platform() + platformPath + '.' + namespace); | |
if (platformConfig || platformConfig === false) { | |
return platformConfig; | |
} | |
// didnt find a specific platform config, now try the default | |
return stringObj(configProperties.platform, 'default' + platformPath + '.' + namespace); | |
} | |
return configObj[namespace]; | |
}; | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment