forked from cuixiaorui/mini-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
d1c79b0
commit 5cf732b
Showing
9 changed files
with
76 additions
and
3 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
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,20 @@ | ||
{ | ||
"0 debug pnpm:scope": { | ||
"selected": 1, | ||
"workspacePrefix": "/Users/cxr/projects/mini-vue/code/mini-vue" | ||
}, | ||
"1 error pnpm": { | ||
"errno": 1, | ||
"code": "ELIFECYCLE", | ||
"pkgid": "@mini-vue/[email protected]", | ||
"stage": "test", | ||
"script": "jest \"runtime-core\"", | ||
"pkgname": "@mini-vue/runtime-core", | ||
"err": { | ||
"name": "pnpm", | ||
"message": "@mini-vue/[email protected] test: `jest \"runtime-core\"`\nExit status 1", | ||
"code": "ELIFECYCLE", | ||
"stack": "pnpm: @mini-vue/[email protected] test: `jest \"runtime-core\"`\nExit status 1\n at EventEmitter.<anonymous> (/opt/homebrew/Cellar/pnpm/6.32.4/libexec/lib/node_modules/pnpm/dist/pnpm.cjs:105736:20)\n at EventEmitter.emit (node:events:527:28)\n at ChildProcess.<anonymous> (/opt/homebrew/Cellar/pnpm/6.32.4/libexec/lib/node_modules/pnpm/dist/pnpm.cjs:92297:18)\n at ChildProcess.emit (node:events:527:28)\n at maybeClose (node:internal/child_process:1092:16)\n at Process.ChildProcess._handle.onexit (node:internal/child_process:302:5)" | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,5 +1,12 @@ | ||
// todo | ||
// 实现 render 的渲染接口 | ||
// 实现序列化 | ||
import { createRenderer } from "@mini-vue/runtime-core"; | ||
import { extend } from "@mini-vue/shared"; | ||
import { nodeOps } from "./nodeOps"; | ||
import { patchProp } from "./patchProp"; | ||
|
||
export const { render } = createRenderer(extend({ patchProp }, nodeOps)); | ||
|
||
export * from "./nodeOps"; | ||
export * from "./serialize" |
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,27 @@ | ||
export const enum NodeTypes { | ||
ELEMENT = "element", | ||
} | ||
|
||
let nodeId = 0; | ||
// 这个函数会在 runtime-core 初始化 element 的时候调用 | ||
function createElement(tag: string) { | ||
// 如果是基于 dom 的话 那么这里会返回 dom 元素 | ||
// 这里是为了测试 所以只需要反正一个对象就可以了 | ||
// 后面的话 通过这个对象来做测试 | ||
const node = { | ||
tag, | ||
id: nodeId++, | ||
type: NodeTypes.ELEMENT, | ||
props: {}, | ||
children: [], | ||
}; | ||
|
||
return node; | ||
} | ||
|
||
|
||
function insert () { | ||
|
||
} | ||
|
||
export const nodeOps = { createElement,insert }; |
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,3 @@ | ||
export function patchProp(el, key, prevValue, nextValue) { | ||
el[key] = nextValue; | ||
} |
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,10 @@ | ||
// 把 node 给序列化 | ||
// 测试的时候好对比 | ||
// 序列化: 把一个对象给处理成 string (进行流化) | ||
export function serialize(node) { | ||
return serializeElement(node); | ||
} | ||
|
||
function serializeElement(node) { | ||
return `<${node.tag}></${node.tag}>`; | ||
} |
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