Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
forked fromvuejs/vue

Commit846f4a2

Browse files
committed
implement progressive boot with requestIdleCallback
1 parent68abdc3 commit846f4a2

File tree

2 files changed

+32
-25
lines changed

2 files changed

+32
-25
lines changed

‎.eslintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"extends": "vue",
55
"plugins": ["flowtype"],
66
"globals": {
7-
"__WEEX__": true
7+
"__WEEX__": true,
8+
"requestIdleCallback": true
89
},
910
"rules": {
1011
"no-useless-escape": 0,

‎src/core/vdom/patch.js

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ import { registerRef } from './modules/ref'
2020

2121
exportconstemptyNode=newVNode('',{},[])
2222

23+
// used for delaying component mounting for "progressive boot"
24+
consthasRIC=typeofrequestIdleCallback!=='undefined'
25+
2326
consthooks=['create','activate','update','remove','destroy']
2427

2528
functionisUndef(s){
@@ -87,7 +90,14 @@ export function createPatchFunction (backend) {
8790
letinPre=0
8891
functioncreateElm(vnode,insertedVnodeQueue,parentElm,refElm,nested){
8992
vnode.isRootInsert=!nested// for transition enter check
90-
if(createComponent(vnode,insertedVnodeQueue,parentElm,refElm)){
93+
if(isDef(vnode.componentOptions)){
94+
if(hasRIC&&vnode.componentOptions.Ctor.options.bootAsync){
95+
requestIdleCallback(()=>{
96+
createComponent(vnode,insertedVnodeQueue,parentElm,refElm)
97+
})
98+
}else{
99+
createComponent(vnode,insertedVnodeQueue,parentElm,refElm)
100+
}
91101
return
92102
}
93103

@@ -158,23 +168,11 @@ export function createPatchFunction (backend) {
158168
}
159169

160170
functioncreateComponent(vnode,insertedVnodeQueue,parentElm,refElm){
161-
leti=vnode.data
162-
if(isDef(i)){
163-
constisReactivated=isDef(vnode.child)&&i.keepAlive
164-
if(isDef(i=i.hook)&&isDef(i=i.init)){
165-
i(vnode,false/* hydrating */,parentElm,refElm)
166-
}
167-
// after calling the init hook, if the vnode is a child component
168-
// it should've created a child instance and mounted it. the child
169-
// component also has set the placeholder vnode's elm.
170-
// in that case we can just return the element and be done.
171-
if(isDef(vnode.child)){
172-
initComponent(vnode,insertedVnodeQueue)
173-
if(isReactivated){
174-
reactivateComponent(vnode,insertedVnodeQueue,parentElm,refElm)
175-
}
176-
returntrue
177-
}
171+
constisReactivated=isDef(vnode.child)&&vnode.data.keepAlive
172+
vnode.data.hook.init(vnode,false/* hydrating */,parentElm,refElm)
173+
initComponent(vnode,insertedVnodeQueue)
174+
if(isReactivated){
175+
reactivateComponent(vnode,insertedVnodeQueue,parentElm,refElm)
178176
}
179177
}
180178

@@ -481,13 +479,16 @@ export function createPatchFunction (backend) {
481479
}
482480
vnode.elm=elm
483481
const{ tag, data, children}=vnode
484-
if(isDef(data)){
485-
if(isDef(i=data.hook)&&isDef(i=i.init))i(vnode,true/* hydrating */)
486-
if(isDef(i=vnode.child)){
487-
// child component. it should have hydrated its own tree.
488-
initComponent(vnode,insertedVnodeQueue)
489-
returntrue
482+
if(isDef(vnode.componentOptions)){
483+
// child component. it should have hydrated its own tree.
484+
if(hasRIC&&vnode.componentOptions.Ctor.options.bootAsync){
485+
requestIdleCallback(()=>{
486+
hydrateComponent(vnode,insertedVnodeQueue)
487+
})
488+
}else{
489+
hydrateComponent(vnode,insertedVnodeQueue)
490490
}
491+
returntrue
491492
}
492493
if(isDef(tag)){
493494
if(isDef(children)){
@@ -530,6 +531,11 @@ export function createPatchFunction (backend) {
530531
returntrue
531532
}
532533

534+
functionhydrateComponent(vnode,insertedVnodeQueue){
535+
vnode.data.hook.init(vnode,true/* hydrating */)
536+
initComponent(vnode,insertedVnodeQueue)
537+
}
538+
533539
functionassertNodeMatch(node,vnode){
534540
if(vnode.tag){
535541
return(

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp