Skip to content

Commit

Permalink
πŸ“ 두선아 2024-03-04
Browse files Browse the repository at this point in the history
  • Loading branch information
dusunax committed Mar 4, 2024
1 parent 2fe6227 commit 05d2b9b
Show file tree
Hide file tree
Showing 2 changed files with 157 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/dusunax/dil/2024-03-03.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

| DIL μ£Όμ°¨ | λ²”μœ„ | λ°œν‘œ μ€€λΉ„ | λ‚΄μš© | 였늘차 진도 |
| -------- | ------ | --------- | ------------------------------ | ----------- |
| 1μ£Όμ°¨ | 1, 2μž₯ | Bμ‘°: 2μž₯ | λ¦¬μ•‘νŠΈ ν•΅μ‹¬μš”μ†Œμ™€ μžλ°”μŠ€ν¬λ¦½νŠΈ | 20p ~ 25p쀑 |
| 1μ£Όμ°¨ | 1, 2μž₯ | Bμ‘°: 2μž₯ | λ¦¬μ•‘νŠΈ ν•΅μ‹¬μš”μ†Œμ™€ μžλ°”μŠ€ν¬λ¦½νŠΈ | 20p ~ 26p쀑 |

> `였늘 읽은 λ‚΄μš©μ„ markdown으둜 κ°„λ‹¨νžˆ λ©”λͺ¨`
> 읽은 μ‹œκ°„: 5μ‹œ 50λΆ„~9μ‹œ
Expand Down
156 changes: 156 additions & 0 deletions docs/dusunax/dil/2024-03-04.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
# DIL: λͺ¨λ˜ λ¦¬μ•‘νŠΈ λ”₯ λ‹€μ΄λΈŒ, 1μ£Όμ°¨-3

> μŠ€ν„°λ””: μ›”κ°„ CS, https://github.com/monthly-cs/2024-03-modern-react-deep-dive
> 였늘 진행: κ°œμΈκ³΅λΆ€
---

## DIL-week1-3_2024-03-04

| DIL μ£Όμ°¨ | λ²”μœ„ | λ‚΄μš© | 였늘차 진도 |
| -------- | ------ | ------------------------------ | ----------- |
| 1μ£Όμ°¨ | 1, 2μž₯ | λ¦¬μ•‘νŠΈ ν•΅μ‹¬μš”μ†Œμ™€ μžλ°”μŠ€ν¬λ¦½νŠΈ | 26p쀑~59p |

> `였늘 읽은 λ‚΄μš©μ„ markdown으둜 κ°„λ‹¨νžˆ λ©”λͺ¨`
> 읽은 μ‹œκ°„: 9μ‹œλ°˜~12μ‹œ
> λΉ λ₯΄κ²Œ 읽기~!
## 객체

- κ°μ²΄λŠ”? μ°Έμ‘° νƒ€μž…μ΄λ‹€~ reference type이닀~
- κ°μ²΄λŠ”? λ³€κ²½ κ°€λŠ₯ν•˜λ‹€~ writable이닀~
- κ°μ²΄λŠ”? 볡사할 λ•Œ μ°Έμ‘°λ₯Ό μ „λ‹¬ν•œλ‹€~ 동등 비ꡐ가 μ•ˆλœλ‹€~ !==~

### Object.is

- [ES6(ES2015)] μ–˜λ„ 객체 λΉ„κ΅λŠ” !==
- `Object.is({},{}) // false`

### λ¦¬μ•‘νŠΈμ˜ 동등 λΉ„κ΅λŠ” Object.isλ‹€?!?

- objectIs: ES6 폴리필

```tsx
function is(x: any, y: any) {
return (
(x === y && (x !== 0 || 1 / x === 1 / y)) || (x !== x && y !== y) // eslint-disable-line no-self-compare
);
}

const objectIs: (x: any, y: any) => boolean =
typeof Object.is === "function" ? Object.is : is;

export default objectIs;
```

- shallowEqual: 객체 κ°„ 비ꡐ(Object.is + λ°°μ—΄ 길이 + ν‚€ 비ꡐ + κ°’ 비ꡐ)
- Object.is와 달리 => React의 shallowEqual은 μ°Έμ‘°κ°€ λ‹€λ₯Έ 객체도 1 depthκΉŒμ§€λŠ” 비ꡐ가 κ°€λŠ₯ν•˜λ‹€~

```tsx
export default function shallowEqual(objA: mixed, objB: mixed): boolean {
if (is(objA, objB)) return true;

if (
typeof objA !== "object" ||
objA === null ||
typeof objB !== "object" ||
objB === null
)
return false;

const keysA = Object.keys(objA); // ν‚€
const keysB = Object.keys(objB);

if (keysA.length !== keysB.length) return false; // λ°°μ—΄ 길이 비ꡐ

for (let i = 0; i < keysA.length; i++) {
const currentKey = keyA[i];
if (
!hasOwnProperty.call(objB, currentKey) ||
!is(objA[currentKey], objB[currentKey])
)
return false;
}

return true;
}
```

- JSX propsλŠ” 객체닀~ 얕은 비ꡐλ₯Ό ν•œλ‹€~
- 즉, props에 또 λ‹€λ₯Έ 객체λ₯Ό λ„˜κ²¨μ€€λ‹€λ©΄~? μ˜ˆμƒμΉ˜ λͺ»ν•˜κ²Œ μž‘λ™ν•  수 μžˆλ‹€~~
- μžλ°”μŠ€ν¬λ¦½νŠΈμ˜ νŠΉμ§• => 객체 λΉ„κ΅μ˜ λΆˆμ™„μ „μ„±, 얕은 λΉ„κ΅λ§Œ μ‚¬μš©ν•΄μ„œ ν•„μš”ν•œ κΈ°λŠ₯을 κ΅¬ν˜„ν•˜κ³  μžˆλ‹€.

## ν•¨μˆ˜

- ν•¨μˆ˜λž€?
- μž‘μ—…μ„ μˆ˜ν–‰ν•˜κ±°λ‚˜, 값을 κ³„μ‚°ν•˜λŠ” λ“±μ˜ 과정을 => ν•˜λ‚˜μ˜ λΈ”λ‘μœΌλ‘œ κ°μ‹Έμ„œ μ‹€ν–‰ λ‹¨μœ„λ‘œ λ§Œλ“  것

1. ν•¨μˆ˜ 선언문은? λ¬Έ statement이닀~ 그런데?? μ½”λ“œ λ¬Έλ§₯에 따라 ν‘œν˜„μ‹μœΌλ‘œλ„ μ‚¬μš©λ  수 μžˆλ‹€~ (JS 엔진은 λͺ» 말렀~)

```tsx
const sum = function sum(a, b) {
return a + b;
};

sum(10, 24); // 34
```

2. ν•¨μˆ˜ ν‘œν˜„μ‹μ€? λ³€μˆ˜μ— ν• λ‹Ή, ν•¨μˆ˜λͺ…을 주둜 μƒλž΅

- 일급 객체: λ§€κ°œλ³€μˆ˜, λ°˜ν™˜κ°’, ν• λ‹Ή λ‹€ κ°€λŠ₯

3. Function μƒμ„±μžλŠ”? ν•¨μˆ˜ λͺΈν†΅μ΄ λ¬Έμžμ—΄, ν΄λ‘œμ € μƒμ„±λ˜μ§€ μ•ŠμŒ
4. ν™”μ‚΄ν‘œ ν•¨μˆ˜λŠ”? μƒμ„±μž ν•¨μˆ˜λ‘œ x, arguments μ—†μŒ

- thisλž€? μžμ‹ μ΄ μ†ν•œ κ°μ²΄λ‚˜, μžμ‹ μ΄ 생성할 μΈμŠ€ν„΄μŠ€λ₯Ό κ°€λ¦¬ν‚€λŠ” κ°’
- ν™”μ‚΄ν‘œ ν•¨μˆ˜μ˜ thisλŠ”? μƒμœ„ μŠ€μ½”ν”„ this~ => λ³„λ„μ˜ μž‘μ—… 없이 μƒμœ„ this에 μ ‘κ·Ό

### IIFE, Immediately Invoked Function Expression

- κΈ€λ‘œλ²Œ μŠ€μ½”ν”„λ₯Ό μ˜€μ—Όμ‹œν‚€μ§€ μ•ŠλŠ” 독립적인 ν•¨μˆ˜ μŠ€μ½”ν”„λ₯Ό 운용
- 캑슐~

### Higher Order Function / Higher Order Component

- κ³ μ°¨ ν•¨μˆ˜~ 일급 객체~ κ³ μ°¨ μ»΄ν¬λ„ŒνŠΈ~

### 순수 ν•¨μˆ˜ Pure Component

- λΆ€μˆ˜ 효과 side-effect κ°€ μ—†λŠ” ν•¨μˆ˜
- useEffectλ₯Ό μ€„μ΄μž μ§„μ§œλ‘œ

### ν•¨μˆ˜λ₯Ό μž‘κ²Œ λ§Œλ“€μ–΄λΌ

- max-lines-per-function, 50쀄~
- Malcolm Douglas McIlroy => Do One Thing and Do It Well. ν•¨μˆ˜λŠ” ν•˜λ‚˜μ˜ 일을, κ·Έ ν•˜λ‚˜λ§Œ 잘 ν•˜λ©΄ λœλ‹€.

## 클래슀

- React 16.8 μ΄μ „μ—λŠ”? 클래슀 μ»΄ν¬λ„ŒνŠΈ
- [ES2019] #으둜 private
- Typescript: private, protected, public
- μΈμŠ€ν„΄μŠ€ λ©”μ„œλ“œ == ν”„λ‘œν† νƒ€μž… λ©”μ„œλ“œ

```tsx
const myCar = new Car("μ°¨μ°¨μ°¨");

Object.getPrototypeOf(myCar) === Car.prototype; // true
myCar.__proto__ === Car.prototype; // true
```

- πŸ“Œ `__proto__`λ₯Ό μ“°λ©΄ μ•ˆλœλ‹€ => μ™œλƒ? `typeof null === 'object'` 처럼, μ˜λ„μš΄ ν‘œμ€€μ€ μ•„λ‹ˆμ§€λ§Œ κ³Όκ±° λΈŒλΌμš°μ €μ˜ ν˜Έν™˜μ„±μ„ 지킀기 μœ„ν•΄μ„œλ§Œ μ‘΄μž¬ν•˜λŠ” κΈ°λŠ₯이기 λ•Œλ¬Έμž„
- => `Object.getPrototypeOf`λ₯Ό μ“°μž
- prototype chaining μ˜ˆμ‹œ => `Object`의 `toString()`

### ν΄λž˜μŠ€μ™€ ν•¨μˆ˜

- ES6 μ΄μ „μ—λŠ” ν”„λ‘œν† νƒ€μž…μœΌλ‘œ 클래슀 μž‘λ™ 방식을 κ΅¬ν˜„ν–ˆμŒ
- 바벨 트랜슀파일링: \_createClass λΌλŠ” 헬퍼 ν•¨μˆ˜λ₯Ό λ§Œλ“€μ–΄ => ν΄λž˜μŠ€μ™€ λ™μΌν•œ λ°©μ‹μœΌλ‘œ λ™μž‘ν•˜λ„λ‘ 함
- prototype 기반, μƒμ„±μž ν•¨μˆ˜λ‘œ μœ μ‚¬ν•˜κ²Œ μž¬ν˜„ / ν΄λž˜μŠ€λŠ” syntactic sugar

---

```
μ˜μ–΄
Strict Equality Operator, 동등 μ—°μ‚°μž / Equality Operator, 일치 μ—°μ‚°μž
```

0 comments on commit 05d2b9b

Please sign in to comment.