Skip to content

Instantly share code, notes, and snippets.

Mike Cavaliere mcavaliere

Block or report user

Report or block mcavaliere

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View es6-obj-class-conversion-final-result.js
// 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 ) {
View es6-obj-class-conversion-change-static-method-call.js
// Old
if ( ! Utils.configSettingExists( config, 'foo' ) ) {
Utils.printConfigFormatInstructions();
}
// New
if ( ! Config.configSettingExists( 'foo' ) ) {
Config.printConfigFormatInstructions();
View es6-obj-class-conversion-add-instantiation.js
// Old
import Utils from 'utils.js';
// Load the config.
let config = Utils.initConfig();
// New
import Config from 'config.js';
Config.initConfig();
View es6-obj-class-conversion-make-methods-static.js
export default class {
// ...
static printConfigFormatInstructions() {
console.log('Your config file must be in json format, and contain the following keys: foo, bar, baz.');
}
}
View es6-obj-class-conversion-save-data-to-instance.js
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
View es6-obj-class-conversion-initial-references.js
import Utils from 'utils.js';
// Load the config.
let config = Utils.initConfig();
// Later, use it
if ( ! Utils.configSettingExists( config, 'foo' ) ) {
Utils.printConfigFormatInstructions();
}
View es6-obj-class-conversion-change-obj-def.js
// Old
export default {
// ...
}
// New
export default class {
// ...
}
View es6-obj-class-conversion-initial-obj.js
export default {
configSettingExists( config, key ) {
// Search the config object for the key value
let found = Object.keys( config ).indexOf( key )
return found;
},
indexArrayBy(arr, attrName, group=false) {
// ...
},
@mcavaliere
mcavaliere / AsyncStorageSupplement.js
Last active Jul 2, 2018
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
View AsyncStorageSupplement.js
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))
@mcavaliere
mcavaliere / rn-design-systems-color-constants.js
Last active Apr 25, 2018
React Native Design Systems: Typography Constants
View rn-design-systems-color-constants.js
import Colors from './colors';
export default const Typography = {
heading1: {
fontSize: 30,
fontWeight: 'bold',
lineHeight: 32,
color: Colors.black
},
You can’t perform that action at this time.