c24165b8bc
에이전트 8종(대화형/프로그래머 C·S/디자이너/설계자/기획자/QA/PD/PM)에게 [공통 기본 능력 + 롤별 Specialty] 2층으로 지식을 주입하기 위한 재분류. 문서 내용·포맷은 무수정, 폴더 이동만 (6,372개 문서 수 보존 확인). - Topic_Programming → Domain_Programming (내부 구조 보존) - Topic_Graphic → Domain_Design - Topic_Business → Domain_Product - Topic_General → Domain_General - _Common 신설: Math(구 Topic_Math_Specialty), Reasoning(구 General/From_Thinking & Reasoning), Reasoning_Creativity(구 General/From_창의성), Communication(Poetic_Blog_Writing + From_writing) - 타 도메인의 From_* 폴더는 유지 (출처 표기일 뿐, 이미 도메인에 맞게 분류된 문서) - 빈 폴더 정리 (memory/procedures) - 에이전트→폴더 매핑은 workspace의 .astra/agent-knowledge-map.json (9개 에이전트) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
3.5 KiB
3.5 KiB
id, title, category, status, source_trust_level, verification_status, created_at, updated_at, tags, tech_stack, applied_in, aliases
| id | title | category | status | source_trust_level | verification_status | created_at | updated_at | tags | tech_stack | applied_in | aliases | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| js-structured-clone | JS Structured Clone & Deep Equality 함정 | Coding | draft | B | conceptual | 2026-05-09 | 2026-05-09 |
|
|
|
Structured Clone & Deep Equality
JSON.parse(JSON.stringify(x))가 deep clone 의 default 였던 시절은 끝.structuredClone()가 native (Node 17+/모던 브라우저). 단 함수, DOM, class instance 일부는 여전히 못 함.
📖 핵심 개념
- structuredClone: HTML structured clone algorithm. 깊은 복사. circular ref OK. Map/Set/Date/RegExp/TypedArray 지원. 함수/Symbol/DOM 못 함.
- JSON 방식: 함수/undefined/Date 손실, circular 폭사. 절대 production default X.
- Lodash
_.cloneDeep: 거의 모든 형식 지원. 외부 의존성.
💻 코드 패턴
기본 deep clone
const original = { a: 1, b: { c: [1, 2, 3] }, d: new Date() };
const clone = structuredClone(original);
clone.b.c.push(4);
// original.b.c === [1,2,3] 그대로
못 하는 것
const obj = {
fn: () => 1, // ❌ throws DataCloneError
el: document.body, // ❌ DOM
cls: new MyClass(), // ❌ class instance (plain prototype 만)
sym: Symbol('s'), // ❌
};
structuredClone(obj); // 폭사
Class instance 클로닝
class User {
constructor(public name: string, public meta: object) {}
}
// structuredClone 은 prototype 잃음
const u = new User('a', { x: 1 });
const c = structuredClone(u); // c instanceof User === false
// 해결: clone 메서드 직접
class User {
clone(): User { return new User(this.name, structuredClone(this.meta)); }
}
Deep equality
import { dequal } from 'dequal'; // 또는 lodash isEqual
dequal({ a: 1, b: [2] }, { a: 1, b: [2] }); // true
// Reference equality (===)는 빠르지만 객체 내부 같은지 모름
// JSON.stringify 비교는 키 순서 / NaN / Date 정확 X
Circular safe stringify
import { stringify } from 'safe-stable-stringify';
// circular 있으면 [Circular] 마커
🤔 의사결정 기준
| 데이터 | 도구 |
|---|---|
| Plain object / array / Date / Map / Set | structuredClone |
| 함수 / DOM / class instance | 직접 clone 메서드 + structuredClone 재귀 |
| 비교 (deep eq) | dequal 또는 lodash isEqual |
| 빠른 immutability + structural sharing | Immer / immutable.js |
| 직렬화 (network, storage) | JSON or msgpack — 의도적 손실 OK |
❌ 안티패턴
- JSON.parse(JSON.stringify(x)) 를 deep clone default: Date → string, undefined 손실, circular 폭사. 알면서 쓰는 경우만.
Object.assign({}, x)으로 deep clone 기대: shallow.{...x}로 deep clone 기대: shallow.- 가변 객체에 structuredClone 매번: 성능. 진짜 필요할 때만 clone.
- lodash isEqual 매 렌더: 큰 객체 비교 비용. memo + selector.
- NaN === NaN false 예상 못함: deep eq 라이브러리 사용.
- TypedArray byteOffset 바뀜: structuredClone OK 지만 이후 backing buffer 다름.
🤖 LLM 활용 힌트
- "deep clone = structuredClone, deep eq = dequal" 디폴트.
- 함수 / class instance 가 있으면 명시적 clone 메서드.