This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const person01 = { | |
name: 'JM' | |
}; | |
const person02 = person01; | |
/** | |
* Mutating `person02` will cause effect also on `person01` because | |
* `person01` was assigned by reference not by value | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let y = 3; | |
/** | |
* The `sum` function is accessing the global variable `y` to compute for the sum | |
*/ | |
const sum = (x) => x + y; | |
/** | |
* Here we are mutating the state of the variable `y` to `6` | |
* which means that the computation of `sum` will now be different |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sum = (x, y) => x + y; | |
/** | |
* We are sure that `sum(3, 3)` will *always* return `6` | |
* because the function `sum` is *pure*. | |
* No matter how many times we call it with the same input, | |
* it will produce the same output | |
*/ | |
const six = sum(3, 3); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useEffect } from 'react'; | |
import { | |
BrowserRouter as Router, | |
Redirect, | |
Route, | |
Switch, | |
} from 'react-router-dom'; | |
import './App.css'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { RouteProps } from 'react-router-dom'; | |
import { GuardFunction } from '../types/guard'; | |
import { tryCatchSync } from '../utils/tryCatch'; | |
export type GuardFunctionArgs = RouteProps; | |
export type GuardFunction = (args: GuardFunctionArgs) => boolean; | |
type User = { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
Route, | |
RouteProps, | |
matchPath, | |
} from 'react-router-dom'; | |
import { GuardFunction } from '../types/guard'; | |
export type ProtectedRouteProps = RouteProps & { | |
guards: GuardFunction[]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
format, | |
isAfter, | |
isSameDay, | |
} from 'date-fns'; | |
import * as Yup from 'yup'; | |
import { tryCatch } from '../../utils/tryCatch'; | |
const validationSchema = Yup.object().shape({ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { format } from 'date-fns'; | |
export const post = async (req, res) => { | |
const { | |
body: { | |
date: unformattedDate, | |
startTime: unformattedStartTime, | |
endTime: unformattedEndTime, | |
}, | |
} = req; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getData = (id) => { | |
if (!id) { | |
throw new Error('No id found'); | |
} | |
return [1, 2, 3, 4, 5].filter(i => i % id); | |
}; | |
const tryCatch = (tryer) => { | |
try { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// mutable variable | |
const getData = (id) => { | |
if (!id) { | |
throw new Error('No id found'); | |
} | |
return [1, 2, 3, 4, 5].filter(i => i % id); | |
}; |