Skip to content

Instantly share code, notes, and snippets.

View sagar-gavhane's full-sized avatar
🏠
Working from home

Sagar sagar-gavhane

🏠
Working from home
View GitHub Profile
@sagar-gavhane
sagar-gavhane / handleInputChange.js
Last active June 30, 2018 11:19
HandleInputChange for React function
handleInputChange(name, value, args = {}) {
const { key, ...restArgs } = args;
let obj = {};
if (typeof key !== 'undefined') {
if (Object.keys(restArgs).length === 0 && restArgs.constructor === Object) {
obj = { ...this.state[key], ...{ [name]: value } };
} else {
obj = { ...this.state[key], ...{ [name]: value, ...restArgs } };
}
@sagar-gavhane
sagar-gavhane / JsxControls.js
Created July 1, 2018 10:41
JSX Control State IFEE
class JsxControls extends Component {
constructor(props) {
super(props);
this.state = {
counter: 100
}
}
render() {
return (
@sagar-gavhane
sagar-gavhane / app.js
Created July 16, 2018 07:32 — forked from acdlite/app.js
Quick and dirty code splitting with React Router v4
// getComponent is a function that returns a promise for a component
// It will not be called until the first mount
function asyncComponent(getComponent) {
return class AsyncComponent extends React.Component {
static Component = null;
state = { Component: AsyncComponent.Component };
componentWillMount() {
if (!this.state.Component) {
getComponent().then(Component => {
@sagar-gavhane
sagar-gavhane / workspace.json
Last active July 19, 2018 12:26
Visual Studio Code Settings
{
"window.zoomLevel": 0,
"editor.fontFamily": "Operator Mono Medium, Menlo, Monaco, 'Courier New', monospace",
"editor.fontSize": 14,
"editor.fontLigatures": true,
"editor.tabSize": 4,
"editor.mouseWheelZoom": true,
"editor.rulers": [120],
"editor.smoothScrolling": true,
"editor.tabCompletion": true,
@sagar-gavhane
sagar-gavhane / config.js
Created July 22, 2018 15:06
environment-dependent-node-js-configuration
// var config = require('./config.js').get(process.env.NODE_ENV);
var config = {
production: {
session: {
key: 'the.express.session.id',
secret: 'something.super.secret'
},
database: 'mongodb://<user>:<pwd>@apollo.modulusmongo.net:27017/db',
twitter: {
@sagar-gavhane
sagar-gavhane / package.json
Created July 23, 2018 13:07 — forked from adamreisnz/package.json
Simple pure npm scripts build process
{
"name": "project-name",
"description": "Template for static sites",
"version": "1.0.0",
"homepage": "http://www.project-name.com",
"author": {
"name": "Adam Buczynski",
"url": "http://adambuczynski.com"
},
"license": "UNLICENSED",
@sagar-gavhane
sagar-gavhane / API.md
Created July 26, 2018 09:27 — forked from iros/API.md
Documenting your REST API

Title

<Additional information about your API call. Try to use verbs that match both request type (fetching vs modifying) and plurality (one vs multiple).>

  • URL

    <The URL Structure (path only, no root url)>

  • Method:

@sagar-gavhane
sagar-gavhane / preventDuplicateToast.js
Created July 27, 2018 05:49
Prevent duplicate toast notification
if (!toast.isActive(this.toastId)) {
const { message } = response.data;
this.toastId = toast.success(message);
}
@sagar-gavhane
sagar-gavhane / difference.js
Created July 27, 2018 09:15 — forked from Yimiprod/difference.js
Deep diff between two object, using lodash
/**
* Deep diff between two object, using lodash
* @param {Object} object Object compared
* @param {Object} base Object to compare with
* @return {Object} Return a new object who represent the diff
*/
function difference(object, base) {
function changes(object, base) {
return _.transform(object, function(result, value, key) {
if (!_.isEqual(value, base[key])) {
@sagar-gavhane
sagar-gavhane / reactLogger.jsx
Last active July 27, 2018 09:21
React logger
// component
shouldComponentUpdate(nextProps, nextState) {
console.group('react-logger');
console.log('[prevProps]', this.props);
console.log('[nextProps]', nextProps);
console.log('[prevState]', this.state);
console.log('[nextState]', nextState);
console.log('[propsChange]', difference(this.props, nextProps));
console.log('[stateChange]', difference(this.state, nextState));
console.groupEnd('react-logger');