@junnyontop-pixel/neo-app 1.1.6 → 1.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/core/NeoCore.js +14 -13
  2. package/package.json +1 -1
package/core/NeoCore.js CHANGED
@@ -2,10 +2,12 @@ export class NeoCore {
2
2
  constructor(state, rootRenderFn, containerId) {
3
3
  this.container = document.getElementById(containerId);
4
4
  this.rootRenderFn = rootRenderFn;
5
+
6
+ // Proxy를 사용하여 state가 바뀔 때마다 자동으로 mount() 호출
5
7
  this.state = new Proxy(state, {
6
8
  set: (target, key, value) => {
7
9
  target[key] = value;
8
- this.mount(); // 상태 변화 시 리렌더링
10
+ this.mount(); // 상태 변화 시 자동으로 리렌더링
9
11
  return true;
10
12
  }
11
13
  });
@@ -13,27 +15,24 @@ export class NeoCore {
13
15
 
14
16
  mount() {
15
17
  if (!this.container) return;
16
- this.container.innerHTML = '';
18
+ this.container.innerHTML = ''; // 화면 초기화
17
19
  const domTree = this.rootRenderFn(this.state);
18
20
  this.container.appendChild(domTree);
19
21
  }
20
22
  }
21
23
 
22
- // 가상 노드를 DOM 요소로 바꾸는 함수
24
+ // 가상 노드를 실제 DOM 요소로 변환하는 함수
23
25
  export function h(tag, props, children = []) {
24
26
  const el = document.createElement(tag);
25
27
 
26
- // 1. ID 설정
28
+ // 1. 속성 및 스타일 설정 (대소문자 주의: innerHTML)
27
29
  if (props.id) el.id = props.id;
28
-
29
- // 2. 스타일 설정
30
30
  if (props.style) Object.assign(el.style, props.style);
31
+
32
+ // 컴파일러(index.js)와 이름을 맞춘 innerHTML 사용
33
+ if (props.innerHTML) el.innerHTML = props.innerHTML;
31
34
 
32
- // 3. 내용물 설정
33
- if (props.innerHtml) el.innerHTML = props.innerHtml;
34
-
35
- // 💡 4. 이벤트 연결 (이 부분이 빠져있을 거예요!)
36
- // props에 on으로 시작하는 속성(onClick 등)이 있다면 이벤트를 등록합니다.
35
+ // 2. 이벤트 연결 (onClick, onInput 등)
37
36
  Object.keys(props).forEach(key => {
38
37
  if (key.startsWith('on') && typeof props[key] === 'function') {
39
38
  const eventType = key.toLowerCase().substring(2); // 'onClick' -> 'click'
@@ -41,9 +40,11 @@ export function h(tag, props, children = []) {
41
40
  }
42
41
  });
43
42
 
44
- // 5. 자식 요소 추가
43
+ // 3. 자식 요소 추가 (문자열과 HTMLElement 모두 대응)
45
44
  children.forEach(child => {
46
- if (child instanceof HTMLElement) {
45
+ if (typeof child === 'string') {
46
+ el.appendChild(document.createTextNode(child));
47
+ } else if (child instanceof HTMLElement) {
47
48
  el.appendChild(child);
48
49
  }
49
50
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@junnyontop-pixel/neo-app",
3
- "version": "1.1.6",
3
+ "version": "1.1.7",
4
4
  "description": "나만의 커스텀 프레임워크 Neo",
5
5
  "main": "core/NeoCore.js",
6
6
  "type": "module",