-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
47 lines (39 loc) · 1.38 KB
/
Copy pathapp.js
File metadata and controls
47 lines (39 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import nodeOps from './nodeOps.js'
import { patch } from './render.js'
import { createVNode } from './vnode.js'
import { effect, track, trigger } from './reactive.js'
function createApp(args) {
const { data, methods, computed: computedData, render } = args
const app = {}
const ctx = { ...data(), ...methods, ...computedData }
// const rawData = data()
app.publicCtx = new Proxy(ctx, {
get(target, key, receiver) {
// console.log('get', target, key)
track(target, key)
return target[key]
},
set(target, key, value, receiver) {
// console.log('set', target, key, value, receiver)
target[key] = value
trigger(target, key)
return true
// const res = target[key] = value
// (index):24 Uncaught TypeError: 'set' on proxy: trap returned falsish for property 'total'
// return res
}
})
// app.render = render
app.mount = function(selector, document) {
const container = nodeOps.querySelector(selector, document)
app.vnode = createVNode()
effect(() => {
// console.log('re rendering')
const nextVNode = render.call(app.publicCtx)
patch(app.vnode, nextVNode, container)
app.vnode = nextVNode
})
}
return app
}
export { createApp }