-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp6.js
128 lines (105 loc) · 5.83 KB
/
app6.js
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
const layout = (cmp, attrs) => {
let onEnterData = undefined
return {
onmatch: () => {
console.log('layout::onmatch')
},
render: () => {
return m('div', {style: 'height: 300px;overflow: hidden;'}, [
'header w/ single oninit',
m('.container', {style: 'width:100%;display:flex;flex-wrap:nowrap'},
m(FLIP, {
oninit: () => console.log('FLIP::oninit'),
enter: (vnodeChild, flip) => {
console.log('enter', onEnterData)
if (onEnterData) {
let enterData = onEnterData(),
outboundKey = enterData.vnodeChildExit.key,
inboundKey = vnodeChild.key,
boundingClients = flip.boundingClients,
boundingOutbound = boundingClients[outboundKey].previous,
boundingInbound = boundingClients[inboundKey].current,
inBound = vnodeChild,
outBound = enterData.vnodeChildExit
let delta = FLIP.delta(boundingOutbound, boundingInbound)
if(m.route.get() === '/first') {
requestAnimationFrame(() => {
requestAnimationFrame(() => {
outBound.dom.style.transform = delta.toTranslate3d()
inBound.dom.style.transform = delta.toTranslate3d()
outBound.dom.style.transition = 'transform 300ms'
inBound.dom.style.transition = 'transform 300ms'
outBound.dom.addEventListener('transitionend', () => {
inBound.dom.style.transform = ''
inBound.dom.style.transition = ''
enterData.resolve()
})
})
})
} else {
let inDelta = FLIP.delta(boundingOutbound, boundingInbound)
let outDelta = FLIP.delta(boundingInbound, boundingOutbound)
inDelta.deltaX *= 2
inBound.dom.style.transform = inDelta.toTranslate3d()
requestAnimationFrame(() => {
requestAnimationFrame(() => {
inDelta.deltaX /= 2
inBound.dom.style.transform = inDelta.toTranslate3d()
outBound.dom.style.transform = outDelta.toTranslate3d()
outBound.dom.style.transition = 'transform 300ms'
inBound.dom.style.transition = 'transform 300ms'
outBound.dom.addEventListener('transitionend', () => {
inBound.dom.style.transform = ''
inBound.dom.style.transition = ''
enterData.resolve()
})
})
})
}
}
},
exit: (vnodeChild, flip) => {
console.log('exit()', vnodeChild, flip)
return setUpPromise(vnodeChild, flip)
}
}, [
m('div', {
key: attrs.pagekey,
style: Object.assign({}, attrs.style, {flex: '0 0 100%'}),
oninit: () => console.log('layout::oninit'),
}, [
m('h1', 'Routed Page Header'),
m('ul', ['/first', '/second'].filter(route => {
return m.route.get() !== route
}).map(route => m('li', m('a', {
href: route,
oncreate: m.route.link
}, route)))
),
m(cmp, attrs)
])
])),
'footer w/ single oninit'
]
)
}
}
function setUpPromise(vnodeChild) {
return new Promise((resolve) => {
onEnterData = () => {
return {
resolve: resolve,
vnodeChildExit: vnodeChild
}
}
})
}
}
const Cmp = {
oninit: () => console.log('Cmp::oninit'),
view: vnode => m('h2', vnode.attrs.title)
}
m.route(document.body, '/first', {
'/first': layout(Cmp, {pagekey: 1, title: 'First Route', style: {backgroundColor: 'aliceblue'}}),
'/second': layout(Cmp, {pagekey: 2, title: 'Second Route', style: {backgroundColor: 'beige'}})
})