Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking β€œSign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[holee] typescript-racingcar #1

Open
wants to merge 35 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
fb58e47
chore: codeformatter, cypress, tsconfig, docs
hochan222 Jun 2, 2021
a155f40
feat: λ²„νŠΌ λˆ„λ₯Όμ‹œ 이름 λ Œλ”λ§
hochan222 Jun 2, 2021
5b2e816
feat: μžλ™μ°¨ 이름 μž…λ ₯μ‹œ 화면에 이름 λ Œλ”λ§ κΈ°λŠ₯ κ΅¬ν˜„
hochan222 Jun 2, 2021
104bb69
bug: button 2κ°œκ°€ ν•œκ°œ 눌린 ν›„ μž‘λ™μ„ μ•ˆν•¨
hochan222 Jun 2, 2021
43f0526
fix: cause=> innerHTML destory eventlistener
hochan222 Jun 2, 2021
c495959
feat: add Winner
hochan222 Jun 2, 2021
02beb8c
refactor: to winner and component
hochan222 Jun 2, 2021
f36b018
refactor: naming component
hochan222 Jun 2, 2021
964800a
feat: reset button κ΅¬ν˜„ μ™„λ£Œ
hochan222 Jun 2, 2021
fa8319a
chore: prettier
hochan222 Jun 2, 2021
65c6699
chore: prettier
hochan222 Jun 2, 2021
691dfac
refactor: func to const val = ()=>{}
hochan222 Jun 3, 2021
471c156
feat: spinner κΈ°λŠ₯ κ΅¬ν˜„
hochan222 Jun 3, 2021
f66feaf
feat: add race async
hochan222 Jun 3, 2021
50e075b
feat: 각 횟수 사이에 μ§€μ—°μ‹œκ°„ 두기 async, await μ‚¬μš©
hochan222 Jun 3, 2021
af30635
feat: μŠ€ν”Όλ„ˆ λ§ˆμ§€λ§‰ 진행 νšŸμˆ˜κ°€ λλ‚˜λ©΄ μ‚­μ œν•˜λ„λ‘ λ³€κ²½
hochan222 Jun 3, 2021
978394d
feat: κΈ°λŠ₯κ΅¬ν˜„: μ •μƒμ μœΌλ‘œ κ²Œμž„μ˜ 턴이 λ‹€ λ™μž‘λœ ν›„μ—λŠ” κ²°κ³Όλ₯Ό 보여주고, 2초 후에 μΆ•ν•˜μ˜ alert 메세지λ₯Ό λ„μš΄λ‹€.
hochan222 Jun 3, 2021
36e7cb3
refactor: @share 폴더λ₯Ό 곡용으둜 λ§Œλ“€κΈ°
hochan222 Jun 3, 2021
a31cfe8
refactor: κ³΅ν†΅μœΌλ‘œ 뺼수 μžˆλŠ”κ±° λ¦¬νŽ™ν† λ§
hochan222 Jun 3, 2021
f6e5b5c
refactor: index.html에 div tag만 남기기
hochan222 Jun 3, 2021
59c0a7a
refactor: μžλ™μ°¨ 이름 μ΄ˆκΈ°ν™” ν•¨μˆ˜ 뢄리
hochan222 Jun 3, 2021
d6b60fb
feat: init νŒŒμΌμ„ λ§Œλ“€μ–΄μ„œ λ”°λ‘œ init에 κ΄€λ ¨ν•œ ν•¨μˆ˜ 둜직 뢄리
hochan222 Jun 3, 2021
543afb2
refactor: delay μ‹œκ°„ μƒμˆ˜λ‘œ λΊ΄κΈ°
hochan222 Jun 3, 2021
6230026
refactor: space before return
hochan222 Jun 3, 2021
58c3797
refactor: render ν•¨μˆ˜ ν˜•μ‹ 톡일화
hochan222 Jun 3, 2021
17f51c2
fix: car name input μž…λ ₯ν•œ λ’€μ—λ§Œ count μž…λ ₯ν•  수 있게 κ΅¬ν˜„ν•˜κΈ°.
hochan222 Jun 3, 2021
26e8f86
feat: car name input μž…λ ₯ν•œ λ’€ λΉ„ν™œμ„±ν™” ν•˜κΈ°.
hochan222 Jun 3, 2021
08476fd
feat: car name input μž…λ ₯ν•œ λ’€ λΉ„ν™œμ„±ν™” ν•˜κΈ°.
hochan222 Jun 3, 2021
e9c8da2
refactor: forwardIconDiv λ₯Ό view둜 λ‚˜λˆ„κΈ°
hochan222 Jun 3, 2021
0a5bc30
refactor: import νŒŒμΌλ“€ μˆœμ„œ λ¦¬νŽ™ν† λ§
hochan222 Jun 3, 2021
f2449fd
test: add cypress testcase
hochan222 Jun 3, 2021
a2c7c10
style: ν•¨μˆ˜μ‚¬μ΄μ— κ°œν–‰ μΆ”κ°€
hochan222 Jun 4, 2021
710237b
refactor: dom ν•¨μˆ˜ queryselector둜 톡일화 및 $, 9620둜 가독성 μ’‹κ²Œ λ°”κΏˆ
hochan222 Jun 4, 2021
581f5e6
refactor: return ν•œμ€„μœ„ κ°œν–‰κ³Ό 선언뢀와 둜직 κ°œν–‰μœΌλ‘œ ꡬ뢄
hochan222 Jun 4, 2021
9419e43
docs: μœ„ κΈ°λŠ₯듀이 μ •μƒμ μœΌλ‘œ λ™μž‘ν•˜λŠ”μ§€ Cypressλ₯Ό μ΄μš©ν•΄ ν…ŒμŠ€νŠΈν•œλ‹€.
hochan222 Jun 7, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: return ν•œμ€„μœ„ κ°œν–‰κ³Ό 선언뢀와 둜직 κ°œν–‰μœΌλ‘œ ꡬ뢄
hochan222 committed Jun 4, 2021
commit 581f5e6c6b2c7cdd5e649ee60ea20e4a2333a5ad
6 changes: 1 addition & 5 deletions dist/js/modules/Winner.js
Original file line number Diff line number Diff line change
@@ -6,11 +6,7 @@ const WinnerComponent = ({ $app, cars }) => {
const findWinners = (cars) => {
const totalDistances = cars.map((car) => car.distance);
const maxDistance = Math.max(...totalDistances);
return cars
.filter((car) => {
return car.distance === maxDistance;
})
.map((winner) => winner.name);
return cars.filter((car) => car.distance === maxDistance).map((winner) => winner.name);
};
const render = (JSX) => {
const sectionElement = $app;
4 changes: 4 additions & 0 deletions src/js/modules/@share/dom-dataset.ts
Original file line number Diff line number Diff line change
@@ -2,16 +2,20 @@ import { $ } from './utils.js';

const setCarNameDataset = (data: string): void => {
const carNamesInput: HTMLInputElement = $('input[type="text"]') as HTMLInputElement;

if (carNamesInput) {
carNamesInput.dataset.click = data;
}
};

const checkCarNameDataset = (): boolean => {
const carNamesInput: HTMLInputElement = $('input[type="text"]') as HTMLInputElement;

if (carNamesInput) {

return carNamesInput.dataset.click === 'click';
}

return false;
};

2 changes: 2 additions & 0 deletions src/js/modules/@share/init.ts
Original file line number Diff line number Diff line change
@@ -2,12 +2,14 @@ import { $ } from './utils.js';

const carNameInputInit = () => {
const carNameInput = $('#car-name-input') as HTMLInputElement;

carNameInput.value = '';
carNameInput.focus();
};

const racingCountInputInit = () => {
const racingCountInput = $('#racing-count-input') as HTMLInputElement;

racingCountInput.value = '';
racingCountInput.focus();
};
3 changes: 3 additions & 0 deletions src/js/modules/@share/utils.ts
Original file line number Diff line number Diff line change
@@ -33,19 +33,22 @@ const enable = (element: HTMLButtonElement | HTMLInputElement) => {

const carNameEnable = () => {
const carNamesInput: HTMLInputElement = $('#car-name-input') as HTMLInputElement;

enable(carNamesInput);
enable(<HTMLButtonElement>carNamesInput.parentElement?.children[1]);
};

const countEnable = () => {
const raceCountInput: HTMLInputElement = $('input[type="number"]') as HTMLInputElement;

enable(raceCountInput);
enable(<HTMLButtonElement>raceCountInput.parentElement?.children[1]);
};

const initEnable = () => {
const carNamesInput: HTMLInputElement = $('#car-name-input') as HTMLInputElement;
const raceCountInput: HTMLInputElement = $('input[type="number"]') as HTMLInputElement;

enable(carNamesInput);
enable(<HTMLButtonElement>carNamesInput.parentElement?.children[1]);
enable(raceCountInput);
2 changes: 2 additions & 0 deletions src/js/modules/CarName.ts
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ const CarNameComponent = ({ $app, carNames }: { $app: HTMLDivElement | null; car

const render = (JSX: string): void => {
const sectionElement: HTMLDivElement | null = $app;

if (sectionElement) {
sectionElement.insertAdjacentHTML('beforeend', JSX);
}
@@ -19,6 +20,7 @@ const CarNameComponent = ({ $app, carNames }: { $app: HTMLDivElement | null; car

const init = (carNames: string): void => {
const carNameList: string[] = carNames.split(',').map((x) => x.trim());

if (checkCarNames(carNameList)) {
setCarNameDataset('click');
render(carNamesSection(carNameList.map((carName) => carNameDiv(carName)).join('')));
1 change: 1 addition & 0 deletions src/js/modules/Game.ts
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ import { startSection } from './@share/view.js';
const Game = ({ $app }: { $app: HTMLDivElement | null }): void => {
const render = (JSX: string): void => {
const sectionElement: HTMLDivElement | null = $app;

if (sectionElement) {
sectionElement.insertAdjacentHTML('beforeend', JSX);
}
2 changes: 2 additions & 0 deletions src/js/modules/Race.ts
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ const RaceComponent = ({ $app, count }: { $app: HTMLDivElement | null; count: nu
let _cars: Car[];

const checkValidCount = (count: number): boolean => {

return count - Math.floor(count) === 0 && count > 0;
};

@@ -23,6 +24,7 @@ const RaceComponent = ({ $app, count }: { $app: HTMLDivElement | null; count: nu
const assignCarsName = (): Car[] => {
const cars: Car[] = [];
const inputCarNames = getInputCarsName();

inputCarNames.forEach((name) => {
cars.push(new Car(name));
});
9 changes: 4 additions & 5 deletions src/js/modules/Winner.ts
Original file line number Diff line number Diff line change
@@ -8,15 +8,12 @@ const WinnerComponent = ({ $app, cars }: { $app: HTMLDivElement | null; cars: Ca
const totalDistances: number[] = cars.map((car) => car.distance);
const maxDistance: number = Math.max(...totalDistances);

return cars
.filter((car) => {
return car.distance === maxDistance;
})
.map((winner) => winner.name);
return cars.filter((car) => car.distance === maxDistance).map((winner) => winner.name);
};

const render = (JSX: string): void => {
const sectionElement: HTMLDivElement | null = $app;

if (sectionElement) {
sectionElement.insertAdjacentHTML('beforeend', JSX);
}
@@ -34,11 +31,13 @@ const WinnerComponent = ({ $app, cars }: { $app: HTMLDivElement | null; cars: Ca
inputController();
initEnable();
setCarNameDataset('');

return;
};

const controller = (): void => {
const retryButton: HTMLButtonElement = $$('button')[2] as HTMLButtonElement;

if (retryButton) {
retryButton.onclick = retryButtonEvent;
}