-
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
219 additions
and
0 deletions.
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,167 @@ | ||
### βοΈ λ§μ΄ν¬λ‘ νμ€ν¬ ν | ||
|
||
- λΉλκΈ° μμ μ μ²λ¦¬νκΈ° μν΄ ECMA μμλ `PromiseJobs` μ΄λΌλ λ΄λΆ Queue λ₯Ό λͺ μνλλ°, V8 μμ§μμλ μ΄λ₯Ό λ§μ΄ν¬λ‘ νμ€ν¬ νλΌκ³ μ μνλ€. | ||
- λ§μ΄ν¬λ‘ νμ€ν¬ νλ νμ€ν¬ νμ λ€λ₯΄κ² λ¨Όμ λ€μ΄μ¨ μμ μ μ°μ νμ¬ μ€ννλ€. (FIFO : First In First Out) | ||
- λͺ¨λ Promise μμ μ κ²½μ° Microtask Queue μ λ€μ΄κ° μ²λ¦¬λκΈ°μ Promise λ λ λΉλκΈ°λ‘ | ||
μλνλ€. | ||
- μΆκ°λ‘ `MutationObserver` κ° λ³νλ₯Ό κ΄μΈ‘ν μ μ€ννλ Callback ν¨μ λν Microtask Queue λ‘ λ€μ΄κ°λ€. | ||
|
||
### βοΈ λ§μ΄ν¬λ‘ νμ€ν¬ νμ νΉμ΄μ | ||
|
||
- Microtask Queue λ΄λΆμ Task λ Call Stack μ΄ λΉμμ λ κ°μ₯ μ΅μ°μ μΌλ‘ μ€νλλ€. | ||
- Microtask Queue λ΄λΆμ μμ μ΄ Call Stack μ μ μ¬λμ΄ μ€νλ λ, μλ‘μ΄ Microtask λ₯Ό μμ±ν μ μλ€. | ||
- λΈλΌμ°μ λ λλ§μ κ²½μ° Microtask Queue λ΄λΆμ μμ μ΄ λͺ¨λ μ€νλμ΄ Queue κ° λΉμμ λ μ€νλλ€. | ||
- λ°λΌμ ν μ¬μ΄ν΄μ μ°μμ μΌλ‘ μλ‘μ΄ Microtask λ₯Ό μμ±νλ κ²μ λΈλΌμ°μ λ λλ§ λ° Task Queue λ΄λΆμ μμ μ **μ§μ°μν¨λ€**. | ||
|
||
### βοΈ κ° λΉλκΈ° Task μ μ€ν μμ μ 리 | ||
|
||
```js | ||
console.log('a'); | ||
|
||
setTimeout(() => { | ||
console.log('b') | ||
}, 0); | ||
|
||
Promise.resolve().then(() => { | ||
console.log('c'); | ||
}) | ||
|
||
window.requestAnimationFrame(() => { | ||
console.log('d') | ||
}) | ||
|
||
|
||
1. console.log('a') κ° Call Stack μ μ μ¬λκ³ , μ€νλλ€. | ||
2. setTimeout μμ μ΄ Task Queue μ ν λΉλλ€. | ||
3. Promise.resolve() μμ μ΄ μνλκ³ , then νΈλ€λ¬ λ΄λΆμ callback μ΄ Micro Task Queue μ ν λΉλλ€. | ||
4. requestAnimationFrame κ° μΈμλ‘ λ°μ callback μ νλ©΄μ΄ λ λλ§ λλ κ³Όμ μμ μ€ννλλ‘ μμ½ (μ€μΌμ€λ§) νλ€. | ||
5. Call Stack μ΄ λΉμμΌλ―λ‘ Micro Task Queue λ΄λΆμ μμ μ κ°μ Έμ `console.log('c')` λ₯Ό μ€ννλ€. | ||
6. Call Stack κ³Ό Micro Task Queue μ΄ μ λΆ λΉμμΌλ―λ‘ λΈλΌμ°μ λ λλ§μ΄ μ§νλλ€. μ΄λ rAF κ° μΈμλ‘ λ°μ `console.log('d')` μ΄ μ€νλλ€. | ||
7. Task Queue μ μλ μμ μ΄ Call Stack μΌλ‘ μ μ¬λκ³ , `console.log('b')` κ° μ€νλλ€. | ||
``` | ||
|
||
### βοΈ [λ²μΈ] rAF μ λμ λ°©μ | ||
|
||
- requestAnimationFrame μ΄ μΈμλ‘ λ°μ callback μ Map of Animation Frame Callbacks μ μ μ₯λλ€. | ||
- μ΄ λ§μΈ μ¦μ rAF μ callback μ λ³λμ Queue κ° μλ **λΈλΌμ°μ λ΄λΆμμ κ΄λ¦¬νλ λ³λμ 곡κ°**μ Map μΌλ‘ μ μ₯λμ΄ μλ€λ μλ―Έλ€. | ||
- ꡬνμ²΄κ° Map μ΄κΈ° λλ¬Έμ rAF μ κ²½μ° `cancelAnimationFrame(id)` λ©μλλ‘ μ·¨μκ° κ°λ₯νλ€. | ||
|
||
> μΆν μκ°μ΄ λ¨μΌλ©΄ μ΄ν΄λ΄μΌ ν λ¬Έμλ€ | ||
- https://stackoverflow.com/questions/77008112/which-queue-is-associated-with-requestanimationframe | ||
- https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#run-the-animation-frame-callbacks | ||
|
||
# βοΈ React μμ μμ£Ό μ°μ΄λ JS λ¬Έλ² | ||
|
||
### βοΈ κ΅¬μ‘° λΆν΄ ν λΉ, μ κ° κ΅¬λ¬Έ | ||
|
||
- κ°μ²΄λ λ°°μ΄ λ΄λΆμ μμλ₯Ό λ³λμ μ μΈλ¬Έ μμ΄ λ³μμ μ§μ μ μΈ λ° ν λΉνκ³ μΆμ λ μ°μΈλ€. | ||
- Default Parameter λ¬Έλ²λ μ¬μ©ν μ μμΌλ, κ°μ΄ undefined μΈ κ²½μ°μλ§ μ μ©λλ€. | ||
- μΆκ°λ‘ κ°μ²΄ ꡬ쑰 λΆν΄ ν λΉμ κ²½μ° ES5λ‘ νΈλμ€νμΌλ§ ν κ²½μ° λ²λ€μ μ¬μ΄μ¦κ° μ»€μ§ μ μλ€. | ||
|
||
```tsx | ||
// λ°°μ΄ κ΅¬μ‘° λΆν΄ ν λΉ | ||
const [isOpen, setIsOpen] = useState(false); | ||
|
||
// κ°μ²΄ ꡬ쑰 λΆν΄ ν λΉ | ||
const Component = ({ totalCount }: PropsType) => { | ||
return (...) | ||
} | ||
``` | ||
|
||
- μ κ° κ΅¬λ¬Έμ κ²½μ° Spread Operator (`...`) λ₯Ό μ¬μ©νμ¬ νΉμ κ°μ²΄λ₯Ό μλ‘μ΄ κ°μ²΄ λ΄λΆμ μ μΈν μ μκ³ , λ°°μ΄ λν κ°μ μλ¦¬λ‘ μ¬μ©μ΄ κ°λ₯νλ€. | ||
|
||
```js | ||
const obj = { a: 1, b: 2 }; | ||
const newObj = { ...obj, c: 3, d: 4 }; | ||
``` | ||
|
||
> κ°μ²΄ ꡬ쑰 λΆν΄ ν λΉμ νΈλμ€νμΌλ§ ꡬ쑰λ₯Ό νν€μ³λ³΄μ. | ||
```js | ||
"use strict"; | ||
|
||
// source κ°μ²΄μμ excluded λ°°μ΄ λ΄ key λ₯Ό μ μΈν λλ¨Έμ§λ₯Ό λ°ννλ ν¨μ | ||
// _objectWithoutPropertiesLoose μλ λ€λ₯΄κ² Symbol Key κ° μλ κ²½μ°λ κ³ λ €νλ€. | ||
function _objectWithoutProperties(source, excluded) { | ||
if (source == null) return {}; | ||
var target = _objectWithoutPropertiesLoose(source, excluded); | ||
var key, i; | ||
|
||
// Symbol ν€κ° μλ€λ©΄ getOwnPropertySymbols λ‘ λͺ©λ‘μ λ°μ μννλ€. | ||
if (Object.getOwnPropertySymbols) { | ||
var sourceSymbolKeys = Object.getOwnPropertySymbols(source); | ||
|
||
// κ°μ²΄ λ΄λΆμ key λ₯Ό μννλ©° excluded μ ν¬ν¨λμ§ μλ λλ¨Έμ§λ₯Ό target μ μΆκ°νλ€. | ||
for (i = 0; i < sourceSymbolKeys.length; i++) { | ||
key = sourceSymbolKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; // ν΄λΉ key κ° excluded λ°°μ΄μ μλ€λ©΄ continue. | ||
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; | ||
target[key] = source[key]; | ||
} | ||
} | ||
return target; | ||
} | ||
|
||
// source κ°μ²΄μμ excluded λ°°μ΄ λ΄ key λ₯Ό μ μΈν λλ¨Έμ§λ₯Ό λ°ννλ ν¨μ | ||
function _objectWithoutPropertiesLoose(source, excluded) { | ||
if (source == null) return {}; | ||
var target = {}; | ||
var sourceKeys = Object.keys(source); // μ¬κΈ°μλ Symbol Key λ₯Ό λ°ννμ§ μλλ€. | ||
var key, i; | ||
|
||
// κ°μ²΄ λ΄λΆμ key λ₯Ό μννλ©° excluded μ ν¬ν¨λμ§ μλ λλ¨Έμ§λ₯Ό target μ μΆκ°νλ€. | ||
for (i = 0; i < sourceKeys.length; i++) { | ||
key = sourceKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; // ν΄λΉ key κ° excluded λ°°μ΄μ μλ€λ©΄ continue. | ||
target[key] = source[key]; | ||
} | ||
return target; | ||
} | ||
var obj = { | ||
a: 1, | ||
b: 2, | ||
c: 3, | ||
d: 4, | ||
}; | ||
var a = obj.a, | ||
b = obj.b, | ||
rest = _objectWithoutProperties(obj, ["a", "b"]); | ||
``` | ||
|
||
1. `_objectWithoutPropertiesLoose` ν¨μ | ||
|
||
- source μΈμλ κ°μ²΄μ΄κ³ , excluded λ°°μ΄μ κ°μ²΄μμ μ κ±°ν key κ°μ λ΄μ λ°°μ΄μ΄λ€. | ||
- source κ°μ²΄μ key λ₯Ό μΆμΆν ν, μ΄λ₯Ό μννλ©° excluded μ ν¬ν¨λλ key λ₯Ό μ μΈν λλ¨Έμ§λ₯Ό target κ°μ²΄μ μΆκ°νλ€. | ||
- μ΄ν target μ λ°ννλ κ²μΌλ‘ ν¨μλ₯Ό μ’ λ£νλ€. | ||
|
||
2. `_objectWithoutProperties` ν¨μ | ||
|
||
- κΈ°λ³Έ 골μλ `_objectWithoutPropertiesLoose` μ κ°μΌλ `Object.keys()` λ©μλκ° Symbol ννμ key λ₯Ό μ°Ύμ§ λͺ»νλ μμΈλ₯Ό μ²λ¦¬νλ λ‘μ§μ΄ μΆκ°λμλ€. | ||
- λ¨Όμ `_objectWithoutPropertiesLoose` ν¨μμ κ²°κ³Ό (target) λ₯Ό μΈκ³ λ°λλ€. | ||
- μ΄ν source κ°μ²΄ λ΄ Symbol νμ μ key λ°°μ΄μ `Object.getOwnPropertySymbols` λ©μλλ‘ λ°λλ€. | ||
- Symbol Key λ°°μ΄μ μννλ©° excluded μ ν΄λΉ key κ° μλ€λ©΄ μ΄λ₯Ό μ μΈνκ³ , μλ€λ©΄ key μ value λ₯Ό target κ°μ²΄μ ν λΉνλ€. | ||
|
||
|
||
### βοΈ Array Map, filter, reduce | ||
|
||
- κΈ°μ‘΄ λ°°μ΄μ μμλ₯Ό μννμ¬ μΈμλ‘ λ°μ callback μ κ²°κ³Όλ₯Ό κΈ°λ°μΌλ‘ μλ‘μ΄ λ°°μ΄μ μμλ₯Ό μΆκ°νλ λ©μλμ΄λ€. | ||
- React μ κ²½μ° λ°°μ΄ν state μ λ³κ²½μΌλ‘ 리λ λλ§μ μ λ°μν€λ €λ©΄ λ©λͺ¨λ¦¬ μ£Όμκ° λ¬λΌμ ΈμΌ νλ€. | ||
- μ λ©μλλ μλ‘μ΄ λ°°μ΄μ μμ±νμ¬ ν λΉνκΈ°μ `Object.is` κΈ°λ°μ λλ±μ± κ²μ¬μμ κ°μ΄ λ¬λΌμ§μ μ λνλ€. | ||
|
||
### βοΈ μΌν 쑰건 μ°μ°μ | ||
|
||
- νΉμ κ°μ κΈ°λ°μΌλ‘ λ€λ₯Έ μ»΄ν¬λνΈλ₯Ό λ΄λΆμμ λ λλ§ νλλ‘ μ½λλ₯Ό μμ±ν μ μλ€. | ||
- if - else κΈ°λ°μ μ½λ λΈλ μμ΄ ν μ€λ‘ κ°κ²°νκ² μ‘°κ±΄λ¬Έμ μΆμ½ν μ μλ€. | ||
|
||
|
||
# βοΈ Typescript | ||
|
||
> μ± μμλ Typescript λ₯Ό λ€λ€μΌ νλ μ΄μ μ λν΄μ μ€λͺ νκΈ°μ κ°κ²°νκ² λ΄μ©λ§ μ 리νκ³ μ νλ€. | ||
1. any λμ unknown μ μ¬μ©νμ. | ||
2. Type Guard, Type Narrow λ₯Ό μ νμ©νμ. | ||
3. Generic μ¬μ©μΌλ‘ νμ μ μ μ°μ±μ λνμ. | ||
4. Index Signature, Mapped Type νμ©μΌλ‘ μ°Έμ‘°ν νμ μ μ¬μ©μ μ½κ² νμ. | ||
|
||
- TS λ₯Ό μ¨μΌ νλ μ΄μ μ λν μ 리λ https://github.com/RookieAND/TIL/blob/master/TS/2023%20TS%20Study/Chapter1.md μ λ¨κ²¨λμλ€. |