-
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.
mod: 初始化element流程、实现组件代理对象、实现shapeFlags、实现注册事件、实现组件props、emit、slots、实…
…现fragment和text类型节点、实现getCurrentInstance
- Loading branch information
jindy
committed
Jun 9, 2022
1 parent
aa7a797
commit 0e7c24e
Showing
31 changed files
with
1,037 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { h } from '../../lib/guide-mini-vue.esm.js' | ||
import { Foo } from './Foo.js' | ||
|
||
export const App = { | ||
name: 'App', | ||
setup(props) {}, | ||
render() { | ||
return h('div', {}, [h('div', {}, 'App', ), h(Foo, { | ||
onAdd(a, b) { | ||
console.log('on add', a, b) | ||
}, | ||
onAddFoo(a, b) { | ||
console.log('onAddFoo', a, b) | ||
} | ||
})]) | ||
} | ||
} |
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,22 @@ | ||
import { h } from "../../lib/guide-mini-vue.esm.js" | ||
|
||
export const Foo = { | ||
name: 'Foo', | ||
setup(props, { emit }) { | ||
const emitAdd = () => { | ||
console.log('emitAdd') | ||
emit('add', 1, 2) | ||
emit('add-foo', 1, 2) | ||
} | ||
return { | ||
emitAdd | ||
} | ||
}, | ||
render() { | ||
const btn = h('button', { | ||
onClick: this.emitAdd | ||
}, 'emitAdd') | ||
const foo = h('p', {}, 'foo') | ||
return h('div', {}, [foo, btn]) | ||
} | ||
} |
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,16 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>emit</title> | ||
</head> | ||
|
||
<body> | ||
<div id="app"></div> | ||
<script type="module" src="./main.js"></script> | ||
</body> | ||
|
||
</html> |
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,6 @@ | ||
|
||
import { createApp } from '../../lib/guide-mini-vue.esm.js' | ||
import { App } from './App.js' | ||
|
||
const rootContainer = document.querySelector('#app') | ||
createApp(App).mount(rootContainer) |
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,16 @@ | ||
import { h, createTextVNode } from '../../lib/guide-mini-vue.esm.js' | ||
import { Foo } from './Foo.js' | ||
|
||
export const App = { | ||
name: 'App', | ||
setup(props) {}, | ||
render() { | ||
const app = h('div', {}, 'App') | ||
const foo = h(Foo, {}, { | ||
header: ({ age }) => [h('p', {}, 'header' + age), createTextVNode('哈哈哈')], | ||
footer: () => h('p', {}, 'footer') | ||
}) | ||
// const foo = h(Foo, {}, h('p', {}, '567')) | ||
return h('div', {}, [app, foo]) | ||
} | ||
} |
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,17 @@ | ||
import { h, renderSlots } from "../../lib/guide-mini-vue.esm.js" | ||
|
||
export const Foo = { | ||
name: 'Foo', | ||
setup(){ | ||
return {} | ||
}, | ||
render() { | ||
const age = 18 | ||
const foo = h('p', {}, 'foo') | ||
return h('div', {}, [ | ||
renderSlots(this.$slots, 'header', { age }), | ||
foo, | ||
renderSlots(this.$slots, 'footer') | ||
]) | ||
} | ||
} |
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,16 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>slots</title> | ||
</head> | ||
|
||
<body> | ||
<div id="app"></div> | ||
<script type="module" src="./main.js"></script> | ||
</body> | ||
|
||
</html> |
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,6 @@ | ||
|
||
import { createApp } from '../../lib/guide-mini-vue.esm.js' | ||
import { App } from './App.js' | ||
|
||
const rootContainer = document.querySelector('#app') | ||
createApp(App).mount(rootContainer) |
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,13 @@ | ||
import { h, getCurrentInstance } from '../../lib/guide-mini-vue.esm.js' | ||
import { Foo } from './Foo.js' | ||
|
||
export const App = { | ||
name: 'App', | ||
setup() { | ||
const instance = getCurrentInstance() | ||
console.log('app', instance) | ||
}, | ||
render() { | ||
return h('div', {}, [h('div', {}, 'currentInstance demo', ), h(Foo)]) | ||
} | ||
} |
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,13 @@ | ||
import { h, getCurrentInstance } from "../../lib/guide-mini-vue.esm.js" | ||
|
||
export const Foo = { | ||
name: 'Foo', | ||
setup() { | ||
const instance = getCurrentInstance() | ||
console.log('foo', instance) | ||
return {} | ||
}, | ||
render() { | ||
return h('div', {}, 'foo') | ||
} | ||
} |
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,16 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>instance</title> | ||
</head> | ||
|
||
<body> | ||
<div id="app"></div> | ||
<script type="module" src="./main.js"></script> | ||
</body> | ||
|
||
</html> |
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,6 @@ | ||
|
||
import { createApp } from '../../lib/guide-mini-vue.esm.js' | ||
import { App } from './App.js' | ||
|
||
const rootContainer = document.querySelector('#app') | ||
createApp(App).mount(rootContainer) |
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,12 +1,37 @@ | ||
import { h } from '../../lib/guide-mini-vue.esm.js' | ||
import { Foo } from './Foo.js' | ||
|
||
window.self = null | ||
export const App = { | ||
name: 'App', | ||
render() { | ||
return h('div', 'hi, ' + this.msg) | ||
window.self = this | ||
return h( | ||
'div', | ||
{ | ||
id: 'root', | ||
class: ['red', 'hard'], | ||
onClick() { | ||
console.log('点我干嘛!') | ||
}, | ||
onMousedown() { | ||
console.log('mousedown') | ||
} | ||
}, | ||
// string | ||
// 'hi, mini-vue' | ||
// 'hi, ' + this.msg | ||
// array | ||
// [ | ||
// h('p', {class: 'red'}, 'hi'), | ||
// h('p', {class: 'blue'}, 'mini-vue'), | ||
// ] | ||
[h('div', {}, 'hi, mini-vue'), h(Foo, { count: 1 })] | ||
) | ||
}, | ||
setup() { | ||
return { | ||
msg: 'mini-vue' | ||
msg: 'mini-vue,king' | ||
} | ||
} | ||
} |
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,11 @@ | ||
import { h } from "../../lib/guide-mini-vue.esm.js" | ||
|
||
export const Foo = { | ||
setup(props) { | ||
console.log('foo', props) | ||
props.count++ | ||
}, | ||
render() { | ||
return h('div', {}, 'foo:' + this.count) | ||
} | ||
} |
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
Oops, something went wrong.