|
6 | 6 | * 🗂️ JSON 기반 Mock 데이터 매니저 |
7 | 7 | */ |
8 | 8 |
|
9 | | -// JSON 파일들을 동적으로 import하는 함수 |
| 9 | +// JSON 파일들 직접 import |
| 10 | +import binaryTreeJson from './binaryTree.json'; |
| 11 | +import bubbleSortJson from './bubbleSort.json'; |
| 12 | +import fibonacciJson from './fibonacci.json'; |
| 13 | +import graphJson from './graph.json'; |
| 14 | +import heapJson from './heap.json'; |
| 15 | +import linkedListJson from './linkedList.json'; |
| 16 | + |
| 17 | +// JSON 예제 파일들을 객체 형태로 export |
| 18 | +export const jsonExamples = [ |
| 19 | + { |
| 20 | + name: 'binaryTree.json', |
| 21 | + type: 'json', |
| 22 | + code: JSON.stringify(binaryTreeJson, null, 2) |
| 23 | + }, |
| 24 | + { |
| 25 | + name: 'bubbleSort.json', |
| 26 | + type: 'json', |
| 27 | + code: JSON.stringify(bubbleSortJson, null, 2) |
| 28 | + }, |
| 29 | + { |
| 30 | + name: 'fibonacci.json', |
| 31 | + type: 'json', |
| 32 | + code: JSON.stringify(fibonacciJson, null, 2) |
| 33 | + }, |
| 34 | + { |
| 35 | + name: 'graph.json', |
| 36 | + type: 'json', |
| 37 | + code: JSON.stringify(graphJson, null, 2) |
| 38 | + }, |
| 39 | + { |
| 40 | + name: 'heap.json', |
| 41 | + type: 'json', |
| 42 | + code: JSON.stringify(heapJson, null, 2) |
| 43 | + }, |
| 44 | + { |
| 45 | + name: 'linkedList.json', |
| 46 | + type: 'json', |
| 47 | + code: JSON.stringify(linkedListJson, null, 2) |
| 48 | + } |
| 49 | +]; |
| 50 | + |
| 51 | +// JSON 데이터 객체 매핑 (파일명 -> 원본 JSON 데이터) |
| 52 | +const jsonDataMap = { |
| 53 | + 'binaryTree': binaryTreeJson, |
| 54 | + 'bubbleSort': bubbleSortJson, |
| 55 | + 'fibonacci': fibonacciJson, |
| 56 | + 'graph': graphJson, |
| 57 | + 'heap': heapJson, |
| 58 | + 'linkedList': linkedListJson |
| 59 | +}; |
| 60 | + |
| 61 | +// JSON 파일들을 동적으로 import하는 함수 (호환성 유지) |
10 | 62 | const importJsonFile = async (filename) => { |
11 | 63 | try { |
12 | | - // 동적 import로 JSON 파일 로드 |
13 | | - const module = await import(`./${filename}.json`); |
14 | | - return module.default; |
| 64 | + // 캐시된 데이터에서 찾기 |
| 65 | + const jsonData = jsonDataMap[filename]; |
| 66 | + if (jsonData) { |
| 67 | + return jsonData; |
| 68 | + } |
| 69 | + console.warn(`⚠️ JSON 파일을 찾을 수 없습니다: ${filename}.json`); |
| 70 | + return null; |
15 | 71 | } catch (error) { |
16 | 72 | console.warn(`⚠️ JSON 파일 로드 실패: ${filename}.json`, error); |
17 | 73 | return null; |
|
0 commit comments