Skip to content

Instantly share code, notes, and snippets.

View sachinKumarGautam's full-sized avatar
🍷
Frontend Engineer, Love ReactJs

Sachin Kumar sachinKumarGautam

🍷
Frontend Engineer, Love ReactJs
View GitHub Profile
import React, { Component } from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import { View, StyleSheet } from 'react-native'
import { TabBar, Icon } from 'antd-mobile'
import homeIcon from '../../../images/home-icon.svg'
var mammals = [
{
name: 'bantu',
behaviour: [2,3,4]
},
{
name: 'mantu',
behaviour: [2,3,4]
},
{
function Animal(name) {
this.name = name;
}
// Example method on the Animal object
Animal.prototype.getName = function() {
return this.name;
}
function Mammal(name, hasHair) {
/** Polymorphism is one of the tenets of Object Oriented Programming (OOP). It is the practice of designing objects to share behaviors and to be able to override shared behaviors with specific ones. Polymorphism takes advantage of inheritance in order to make this happen.
In OOP everything is considered to be modeled as an object. This abstraction can be taken all the way down to nuts and bolts for a car, or as broad as simply a car type with a year, make, and model.
To have a polymorphic car scenario there would be the base car type, and then there would subclasses which would inherit from car and provide their own behaviors on top of the basic behaviors a car would have. For example, a subclass could be TowTruck which would still have a year make and model, but might also have some extra behaviors and properties which could be as basic as a flag for IsTowing to as complicated as the specifics of the lift.
Getting back to the example of people and employees, all employees are people, but all people are n
@sachinKumarGautam
sachinKumarGautam / service-workers.md
Created May 17, 2018 14:43 — forked from lusan/service-workers.md
Stuff I wish I'd known sooner about service workers

Stuff I wish I'd known sooner about service workers

I recently had several days of extremely frustrating experiences with service workers. Here are a few things I've since learned which would have made my life much easier but which isn't particularly obvious from most of the blog posts and videos I've seen.

I'll add to this list over time – suggested additions welcome in the comments or via twitter.com/rich_harris.

Use Canary for development instead of Chrome stable

Chrome 51 has some pretty wild behaviour related to console.log in service workers. Canary doesn't, and it has a load of really good service worker related stuff in devtools.

@sachinKumarGautam
sachinKumarGautam / debounce.js
Created July 18, 2018 11:39
How to use debounce function in react without lodash
function debounce (fn, time) {
let timeoutId
return wrapper
function wrapper (...args) {
if (timeoutId) {
clearTimeout(timeoutId)
}
timeoutId = setTimeout(() => {
timeoutId = null
export function getData(action$) {
return action$.ofType(GET_DATA) // action type for epic to listen changes
.switchMap(data => { // switchMap is used to always get latest stream ( i.e switch to new stream )
return Observable.ajax(getData(data.id)) //some id
.flatMap(results => { // flatmap is used to flatten the inner observables
return Observable.of(
getDataSuccess(results) // success action
)
})
.catch((error, source) => {
@sachinKumarGautam
sachinKumarGautam / fade-in-text.css
Created August 26, 2018 08:23
This gist is for fade in animation of text when page loads
div {
opacity: 0;
animation: fadeIn 1s 0.5s forwards
}
@keyframes fadeIn {
100% {
opcaity: 1
}
}
@sachinKumarGautam
sachinKumarGautam / event-litsener-for-list.js
Created October 8, 2018 06:18
Optimized event litsensers for list for litseners
class SomeComponent extends React.PureComponent {
// Each instance of SomeComponent has a cache of click handlers
// that are unique to it.
clickHandlers = {};
// Generate and/or return a click handler,
// given a unique identifier.
getClickHandler(key) {
const express = require('express')
const next = require('next')
const cookieParser = require('cookie-parser')
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()
const url = require('url')
const path = require('path')
const expressApp = express()