Skip to content

Instantly share code, notes, and snippets.

View codeBelt's full-sized avatar
💭
I may be slow to respond.

Robert S. codeBelt

💭
I may be slow to respond.
View GitHub Profile
@codeBelt
codeBelt / IAppDomId.ts
Last active April 22, 2019 14:45
CRA multiple apps
import {ComponentType} from 'react';
export default interface IAppDomId {
// Component: ComponentType<any>; // TODO: add when used with code splitting
Component: JSX.Element;
domId: string;
}
const path = require('path');
module.exports = function({ env, paths }) {
return {
webpack: {
alias: {
environment: path.join(__dirname, 'src', 'environments', process.env.CLIENT_ENV)
}
},
};
@codeBelt
codeBelt / config-overrides.js for CRA 1.0
Last active April 9, 2019 13:32
Create React App 2.0
const path = require('path');
module.exports = function override(config, env) {
config.resolve.alias = Object.assign({}, config.resolve.alias, {
environment: path.join(__dirname, 'src', 'environments', process.env.NODE_ENV)
});
return config;
};
import {camelCase, kebabCase, lowerCase, snakeCase, startCase, upperCase, upperFirst} from 'lodash';
export default class StringUtility {
static toCamelCase(str) {
return camelCase(str);
}
static toTitleCase(str) {
return startCase(camelCase(str));
const numberArray = new Array(10).fill(1);
console.log(numberArray);
import StringUtility from "./StringUtility";
import Util from "./Util";
export default class PropertyNormalizerUtility {
static normalize(json) {
const dataOrEmptyObject = Boolean(json) ? json : {};
// Makes all property names camelCase so they are consistent in the application.
// Also recursively goes through child objects.
return Util.clone(dataOrEmptyObject, StringUtility.toCamelCase);
import ISomeThingReducerState from './models/ISomeThingReducerState';
import IAction from '../IAction';
import SomeThingAction, {SomeThingActionUnion} from './SomeThingAction';
import OtherThingResponseModel from './models/OtherThingResponseModel';
export default class SomeThingReducer {
private static readonly _initialState: ISomeThingReducerState = {
isLoadingOtherThing: false,
otherThing: null,
};
const {generateTemplateFiles} = require('generate-template-files');
generateTemplateFiles([
// Example of generating multiple files
{
option: 'Create Redux Store',
defaultCase: '(pascalCase)',
entry: {
folderPath: './tools/templates/',
},
import I__store__ReducerState from './models/I__store__ReducerState';
import IAction from '../IAction';
import __store__Action, {__store__ActionUnion} from './__store__Action';
import __model__ResponseModel from './models/__model__ResponseModel';
export default class __store__Reducer {
private static readonly _initialState: I__store__ReducerState = {
isLoading__model__: false,
__model__(camelCase): null,
};
@codeBelt
codeBelt / checkUtility.ts
Last active January 11, 2019 17:00
Error Checker
const typeError = (obj: any) =>
new Error(`check()'s first argument must be a boolean but argument was of type ${typeof obj}`);
const isNotTypeBoolean = (arg: any) => typeof arg !== 'boolean';
/**
* Helper function for throwing errors if a given expression evaluates to false.
* This function is strict and will throw an error the the type of the first
* argument is not "boolean".
*/