Skip to content

Instantly share code, notes, and snippets.

View mcavaliere's full-sized avatar

Mike Cavaliere mcavaliere

View GitHub Profile
// Less Coupled
var CountrySelectClass = function() {
var countriesIveBeenTo = {
'BE': 'Belgium',
'CR': 'Costa Rica',
'IT': 'Italy',
'US': 'United States of America',
'UK': 'United Kingdom'
};
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]]);
@mcavaliere
mcavaliere / AsyncStorageSupplement.js
Last active July 2, 2018 22:09
Workaround for promise issues with AsyncStorage multiSet/multiGet/multiRemove in React Native (unresolved as of 2018-07-02). See: https://github.com/facebook/react-native/issues/14101
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))
// Old
export default {
// ...
}
// New
export default class {
// ...
}
import Utils from 'utils.js';
// Load the config.
let config = Utils.initConfig();
// Later, use it
if ( ! Utils.configSettingExists( config, 'foo' ) ) {
Utils.printConfigFormatInstructions();
}
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
export default class {
// ...
static printConfigFormatInstructions() {
console.log('Your config file must be in json format, and contain the following keys: foo, bar, baz.');
}
}
// Old
import Utils from 'utils.js';
// Load the config.
let config = Utils.initConfig();
// New
import Config from 'config.js';
Config.initConfig();
// Old
if ( ! Utils.configSettingExists( config, 'foo' ) ) {
Utils.printConfigFormatInstructions();
}
// New
if ( ! Config.configSettingExists( 'foo' ) ) {
Config.printConfigFormatInstructions();
// 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 ) {