Skip to content

Instantly share code, notes, and snippets.

View saurabhpati's full-sized avatar

Saurabh Pati saurabhpati

View GitHub Profile
@saurabhpati
saurabhpati / playing-with-react-3.js
Created July 15, 2018 12:34
playing with react
const Result = (props) => {
return (
<div>{props.counter}</div>
);
}
class Button extends React.Component {
handleClick = () => {
this.props.onClickFunction(this.props.incrementValue);
@saurabhpati
saurabhpati / playing-with-react-2
Created July 12, 2018 16:57
component hierarchy
class Button extends React.Component {
render () {
return (
<button onClick={this.props.onClickFunction}>+1</button>
)
}
}
const Result = (props) => {
return (
@saurabhpati
saurabhpati / react-play-begin.js
Created July 12, 2018 16:43
playing with react
class Button extends React.Component {
constructor(props) {
super(props);
this.state = { counter : 0 };
}
render() {
return (
<button onClick={this.handleClick}>{this.state.counter}</button>
);
@saurabhpati
saurabhpati / exceptionHandler.js
Created June 30, 2018 09:20
Implementing a custom $exceptionHandler using factory function in angularjs
angular
.module('demoModule')
.factory('$exceptionHandler', ['$injector', function ($injector) {
return function (...args) {
var http = $injector.get('$http');
var info = {
exception: args[0],
cause: args[1]
};
@saurabhpati
saurabhpati / LogService.cs
Created June 30, 2018 09:16
The logger service and controller to log client side info.
public class LogService
{
private readonly DbContext _context;
public LogService(DbContext context)
{
this._context = context;
}
public async Task LogException(ErrorLog log)
@saurabhpati
saurabhpati / suspiciousService.js
Created June 11, 2018 05:14
This is a suspiciousService
function suspiciousService($q) {
this.doVeryImportantStuff = function (options) {
if (options.throwException) {
throw 'An exception thrown as per required options.'
}
return $q.resolve({ data: 'Data without exception.' });
}
}
@saurabhpati
saurabhpati / pragmaticSuspiciousController.js
Created June 10, 2018 17:08
A pragmatic suspiciousController
function suspiciousController($scope, $log, suspiciousService) {
var options = {
throwException: false // change to false in case no exception is to be thrown.
};
$scope.doImportantStuff = function () {
try {
suspiciousService.doVeryImportantStuff(options)
.then(function (promisedData) {
// Do something with promised data.
@saurabhpati
saurabhpati / suspiciousController.js
Created June 10, 2018 16:51
A suspicious controller where you may want to introduce error handling
function suspiciousController($scope, $log, suspiciousService) {
var options = {
throwException: true // change to false in case no exception is to be thrown.
};
$scope.doImportantStuff = function () {
suspiciousService.doVeryImportantStuff(options)
.then(function (promisedData) {
// Do something with promised data.
$log.log('Doing something with promised data', promisedData);
@saurabhpati
saurabhpati / webpack.config.js
Created May 20, 2018 14:09
webpack.config.js file for setting up a react project with typescript and webpack
const path = require('path'),
webpack = require('webpack'),
HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: {
app: ['./src/app/App.tsx', 'webpack-hot-middleware/client'],
vendor: ['react', 'react-dom']
},
output: {
@saurabhpati
saurabhpati / tsconfig.json
Created May 20, 2018 13:35
tsconfig.json for setting up a project for a React application with typescript
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"jsx": "react",
"module": "commonjs",
"noImplicitAny": true,
"outDir": "./build/",
"preserveConstEnums": true,
"removeComments": true,
"sourceMap": true,