-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
157 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
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, μΌμΉ μ°μ°μ | ||
``` |