Skip to content

Commit

Permalink
mod: 初始化element流程、实现组件代理对象、实现shapeFlags、实现注册事件、实现组件props、emit、slots、实…
Browse files Browse the repository at this point in the history
…现fragment和text类型节点、实现getCurrentInstance
  • Loading branch information
jindy committed Jun 9, 2022
1 parent aa7a797 commit 0e7c24e
Show file tree
Hide file tree
Showing 31 changed files with 1,037 additions and 58 deletions.
17 changes: 17 additions & 0 deletions example/ComponentEmit/App.js
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)
}
})])
}
}
22 changes: 22 additions & 0 deletions example/ComponentEmit/Foo.js
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])
}
}
16 changes: 16 additions & 0 deletions example/ComponentEmit/index.html
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>
6 changes: 6 additions & 0 deletions example/ComponentEmit/main.js
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)
16 changes: 16 additions & 0 deletions example/ComponentSlots/App.js
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])
}
}
17 changes: 17 additions & 0 deletions example/ComponentSlots/Foo.js
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')
])
}
}
16 changes: 16 additions & 0 deletions example/ComponentSlots/index.html
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>
6 changes: 6 additions & 0 deletions example/ComponentSlots/main.js
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)
13 changes: 13 additions & 0 deletions example/Currentinstance/App.js
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)])
}
}
13 changes: 13 additions & 0 deletions example/Currentinstance/Foo.js
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')
}
}
16 changes: 16 additions & 0 deletions example/Currentinstance/index.html
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>
6 changes: 6 additions & 0 deletions example/Currentinstance/main.js
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)
29 changes: 27 additions & 2 deletions example/HelloWorld/App.js
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'
}
}
}
11 changes: 11 additions & 0 deletions example/HelloWorld/Foo.js
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)
}
}
9 changes: 9 additions & 0 deletions example/HelloWorld/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.red {
color: red;
}

.blue {
color: blue
}
</style>
</head>

<body>
Expand Down
Loading

0 comments on commit 0e7c24e

Please sign in to comment.