This file contains 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
// Less Coupled | |
var CountrySelectClass = function() { | |
var countriesIveBeenTo = { | |
'BE': 'Belgium', | |
'CR': 'Costa Rica', | |
'IT': 'Italy', | |
'US': 'United States of America', | |
'UK': 'United Kingdom' | |
}; |
This file contains 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
var MyApp = {}; | |
MyApp.namespace = function() { | |
var ln = arguments.length, i, value, split, x, xln, parts, object; | |
for (i = 0; i < ln; i++) { | |
value = arguments[i]; | |
parts = value.split("."); | |
object = window[parts[0]] = Object(window[parts[0]]); | |
This file contains 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
export default class AsyncStorageSupplement { | |
static multiGet(keys) { | |
return Promise.all( | |
keys.map(key => AsyncStorage.getItem(key)) | |
) | |
} | |
static multiRemove(keys) { | |
return Promise.all( | |
keys.map(key => AsyncStorage.removeItem(key)) |
This file contains 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
// Old | |
export default { | |
// ... | |
} | |
// New | |
export default class { | |
// ... | |
} |
This file contains 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
import Utils from 'utils.js'; | |
// Load the config. | |
let config = Utils.initConfig(); | |
// Later, use it | |
if ( ! Utils.configSettingExists( config, 'foo' ) ) { | |
Utils.printConfigFormatInstructions(); | |
} |
This file contains 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
export default class { | |
initConfig() { | |
this.config = // ... load a json file via AJAX, filesystem, etc. ... | |
return this.config; | |
}, | |
configSettingExists( key ) { | |
// Search the config object for the key value |
This file contains 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
export default class { | |
// ... | |
static printConfigFormatInstructions() { | |
console.log('Your config file must be in json format, and contain the following keys: foo, bar, baz.'); | |
} | |
} |
This file contains 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
// Old | |
import Utils from 'utils.js'; | |
// Load the config. | |
let config = Utils.initConfig(); | |
// New | |
import Config from 'config.js'; | |
Config.initConfig(); |
This file contains 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
// Old | |
if ( ! Utils.configSettingExists( config, 'foo' ) ) { | |
Utils.printConfigFormatInstructions(); | |
} | |
// New | |
if ( ! Config.configSettingExists( 'foo' ) ) { | |
Config.printConfigFormatInstructions(); |
This file contains 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
// Final config.js | |
export default class { | |
init() { | |
this.config = // ... load the object ... | |
// For posterity, but we don't need to return it at the moment. | |
return this.config; | |
}, | |
settingExists( key ) { |