Skip to content

Instantly share code, notes, and snippets.

View sagiavinash's full-sized avatar

Sagi Avinash Varma sagiavinash

View GitHub Profile
@sagiavinash
sagiavinash / createCustomErrorClass.js
Last active March 19, 2020 17:17
Factory function for creating custom Error classes
/* defintion */
const createErrorClass = (name, customConstructor = () => {}) => {
const ctx = {
[name]: class extends Error {
constructor(...args) {
super(name);
customConstructor(this, ...args);
Error.captureStackTrace(this, ctx[name]);
}
}
@sagiavinash
sagiavinash / machine.js
Created March 11, 2020 20:52
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@sagiavinash
sagiavinash / SimpleTextInput_CWRP.js
Created September 12, 2018 13:31
SimpleTextInput with CWRP
class SimpleTextInput extend Component {
state = {
value: this.props.value,
};
componentWillReceiveProps(nextProps) {
if (this.props.value !== nextProps.value) {
this.setState({value: nextProps.value});
}
}
render() {
@sagiavinash
sagiavinash / ReactRouterV4FlowTypes.js
Created September 10, 2018 12:52
Flow Types for React Router V4
/*
* Types for React Router V4
* Example Usage:
* type PropsT = {
* myProp: string,
* } & ContextRouterT<{
* routeParam: string,
* anotherRouteParam: ?string,
* }>
*/
@sagiavinash
sagiavinash / makeEnzymeCollectionsLodashCompatible.js
Last active September 4, 2018 13:20
make enzyme collections lodash compatible
_.mixin({
enzyme: reactWrapper => (
new Proxy(reactWrapper, {
get: (wrapper, prop) => {
const isSymbol = typeof prop === 'symbol';
const isNumber = !isSymbol && !isNaN(Number(prop));
return isNumber ? wrapper.at(prop) : wrapper[prop];
},
})
@sagiavinash
sagiavinash / gitaliases
Last active December 22, 2021 19:14
My Git Aliases
git config --global alias.ci 'commit';
git config --global alias.st 'status';
git config --global alias.br 'branch';
git config --global alias.unstage 'reset HEAD --';
git config --global alias.hist 'log --pretty=format:"%h %ad | %s%d [%an]" --graph --date=short';
git config --global alias.type 'cat-file -t';
git config --global alias.dump 'cat-file -p';
git config --global alias.tree 'log --all --graph --decorate --oneline --simplify-by-decoration';
git config --global alias.als 'config --get-regexp alias';
git config --global alias.clog 'log --pretty=oneline --abbrev-commit';
import { createStore, combineReducers } from 'redux';
const reduceReducers = (reducers) => (state, action) =>
reducers.reduce((result, reducer) => (
reducer(result, action)
), state);
export const storeManager = {
store: null,
reducerMap: {},
// AppContainer.js
import {withRefreshedStore} from 'react-store-manager';
const HomeRoute = Loadable({
loader: withRefreshedStore(import('./HomePageContainer')),
loading: () => <div>Loading...</div>
});
const ProductListRoute = Loadable({
loader: withRefreshedStore(import('./ProductListPageContainer')),
Root.js
|_AppContainer.js
|_App.js
|_loginReducer.js
|_PageContainer.js
|_Page.js
|_pageReducer.js
// HomePageContainer.js
import storeManager from 'react-store-manager';
import homeReducer from './homeReducer';
storeManager.registerReducers({ home: homeReducer });
export default connect(/* mapStateToProps, mapDispatchToProps */)(Page);
// ProductListPageContainer.js
import storeManager from 'react-store-manager';