Skip to content

Instantly share code, notes, and snippets.

@alaboudi
alaboudi / traffic-light-manipulated.ts
Created June 16, 2020 17:32
Traffic Light - Manipulated Enum
Enum TrafficLightColors {
Red = "#ff0000",
Yellow = "#fff600",
Green = "#37ff00"
}
@alaboudi
alaboudi / traffic-light.ts
Last active June 16, 2020 17:32
traffic Light Enum
Enum TrafficLightColors {
Red,
Yellow,
Green
}
const passingTrafficLight: TrafficLightColors = TrafficLightColors.Red; // this will pass
const failingTrafficLight: TrafficLightColors = "green" // :( This will fail
@alaboudi
alaboudi / load-state.js
Created May 6, 2020 20:21
load-state.js
// You and your teammate have been working on a project for two and a half
// weeks. Everything is going well except you notice that one of the functions
// your teammate wrote is failing a test case, which you know to be correct.
// Unfortunately, your teammate is sick today and to make matters worse, you
// realize that you need to demo your project in ten minutes. So you decide
// to try and fix the function. Can you fix it in time for your demo?
////////////////////////////////////////////////////////////////////////////////
const SYMBOLS = [ 'AAPL', 'AMZN', 'MONY', 'PETS', 'PZZA', 'SHOP', 'TSLA', 'WIFI' ];
@alaboudi
alaboudi / checkbox.tsx
Last active April 2, 2020 23:47
Customize checkbox only using css
import styled from "styled-components";
const Checkbox = styled.input.attrs(() => ({
type: 'checkbox'
}))`
appearance: none;
background-color: #ffffff;
border: 1px solid #000000;
box-shadow: 0 1px 2px rgba(0,0,0,0.05), inset 0px -15px 10px -12px rgba(0,0,0,0.05);
padding: 8px;
// scoreboard-reducer.js
const INITIAL_STATE = {
home: 0,
away: 0,
}
export const scoreboardReducer = (state = INITIAL_STATE, action) {
switch (action.type) {
case 'INCREMENT_SCORE':
const scoringSide = action.payload.team
return {...state, [scoringSide]: state[scoringSide] + 1 };
// scoreboard-reducer.js
const INITIAL_STATE = {
home: 0,
away: 0,
}
export const scoreboardReducer = (state = INITIAL_STATE, action) {
switch (action.type) {
case 'INCREMENT_SCORE':
const scoringSide = action.payload.team;
@alaboudi
alaboudi / no-coupling-be-happy.js
Last active March 18, 2019 19:04
Declarative Action Type
// scoreboard-reducer.js
const INITIAL_STATE = {
home: 0,
away: 0,
}
export const scoreboardReducer = (state = INITIAL_STATE, action) {
switch (action.type) {
case 'GOAL_SCORED':
const scoringSide = action.payload.team;
return {...state, [scoringSide]: state.[scoringSide] + 1 };
@alaboudi
alaboudi / coupling-in-component.js
Last active November 29, 2018 13:44
Imperative Action Type
// scoreboard-reducer.js
const INITIAL_STATE = {
home: 0,
away: 0,
}
export const scoreboardReducer = (state = INITIAL_STATE, action) {
switch (action.type) {
case 'INCREMENT_HOME_SCORE':
return {...state, home: state.home + 1 };
case 'INCREMENT_AWAY_SCORE':
@alaboudi
alaboudi / someReducer.wrong.test.js
Last active August 5, 2018 18:57
Incorrect Reducer Initial State Test
import { someReducer, SOME_REDUCER_INITIAL_STATE } from './someReducer.js'
describe('someReducer', () => {
it('should return the correct initial state', () => {
expect(someReducer(undefined, {}).toEqual(SOME_REDUCER_INITIAL_STATE);
});
});
@alaboudi
alaboudi / someReducer.correct.test.js
Last active August 5, 2018 18:57
Correct Reducer Initial State Test
import { someReducer } from './someReducer.js'
describe('someReducer', () => {
it('should return the correct initial state', () => {
expect(someReducer(undefined, {}).toEqual({
prop1: 'someValue1',
prop2: 'someValue2',
.....
});
});