(
factory, //函数工厂
baseCtor, //构造函数或者vue
context //vue实例化 对象
)
| 3450 | |
| 3451 | // 解析异步组件 更新数据 |
| 3452 | function resolveAsyncComponent( |
| 3453 | factory, //函数工厂 |
| 3454 | baseCtor, //构造函数或者vue |
| 3455 | context //vue实例化 对象 |
| 3456 | ) { |
| 3457 | console.log(factory); |
| 3458 | console.log(baseCtor); |
| 3459 | console.log(context); |
| 3460 | |
| 3461 | //如果 有错误 则返回错误信息 |
| 3462 | if (isTrue(factory.error) && isDef(factory.errorComp)) { |
| 3463 | return factory.errorComp |
| 3464 | } |
| 3465 | //成功状态 |
| 3466 | if (isDef(factory.resolved)) { |
| 3467 | return factory.resolved |
| 3468 | } |
| 3469 | //等待状态 |
| 3470 | if (isTrue(factory.loading) && isDef(factory.loadingComp)) { |
| 3471 | return factory.loadingComp |
| 3472 | } |
| 3473 | //环境 |
| 3474 | if (isDef(factory.contexts)) { |
| 3475 | // already pending 已经等待 |
| 3476 | factory.contexts.push(context); |
| 3477 | } else { |
| 3478 | var contexts = factory.contexts = [context]; //转化成数组 |
| 3479 | var sync = true; |
| 3480 | //渲染 |
| 3481 | var forceRender = function () { |
| 3482 | for (var i = 0, l = contexts.length; i < l; i++) { |
| 3483 | //更新数据 观察者数据 |
| 3484 | contexts[i].$forceUpdate(); |
| 3485 | } |
| 3486 | }; |
| 3487 | //成功 状态渲染 |
| 3488 | var resolve = once(function (res) { //确保只是渲染一次 |
| 3489 | // cache resolved |
| 3490 | factory.resolved = ensureCtor(res, baseCtor); |
| 3491 | // invoke callbacks only if this is not a synchronous resolve |
| 3492 | // (async resolves are shimmed as synchronous during SSR) |
| 3493 | //只有在这不是同步解析时才调用回调 |
| 3494 | //(异步解析在SSR期间以同步的方式进行调整) |
| 3495 | if (!sync) { |
| 3496 | //渲染组件更新数据 |
| 3497 | forceRender(); |
| 3498 | } |
| 3499 | }); |
| 3500 | //失败状态 |
| 3501 | var reject = once(function (reason) { |
| 3502 | "development" !== 'production' && warn( |
| 3503 | "Failed to resolve async component: " + (String(factory)) + |
| 3504 | (reason ? ("\nReason: " + reason) : '') |
| 3505 | ); |
| 3506 | if (isDef(factory.errorComp)) { |
| 3507 | factory.error = true; |
| 3508 | //渲染组件更新数据 |
| 3509 | forceRender(); |
no test coverage detected