/* @flow */

import { callHook } from 'core/instance/lifecycle'
import { getFirstComponentChild } from 'core/vdom/helpers/index' const patternTypes = [String, RegExp] function matches (pattern: string | RegExp, name: string): boolean {
if (typeof pattern === 'string') {
return pattern.split(',').indexOf(name) > -1
} else {
return pattern.test(name)
}
} export default {
name: 'keep-alive',
abstract: true,
props: {
include: patternTypes,
exclude: patternTypes
},
created () {
this.cache = Object.create(null)
},
render () {
const vnode: VNode = getFirstComponentChild(this.$slots.default)
if (vnode && vnode.componentOptions) {
const opts: VNodeComponentOptions = vnode.componentOptions
// check pattern
const name = opts.Ctor.options.name || opts.tag
if (name && (
(this.include && !matches(this.include, name)) ||
(this.exclude && matches(this.exclude, name))
)) {
return vnode
}
const key = vnode.key == null
// same constructor may get registered as different local components
// so cid alone is not enough (#3269)
? opts.Ctor.cid + (opts.tag ? `::${opts.tag}` : '')
: vnode.key
if (this.cache[key]) {
vnode.child = this.cache[key].child
} else {
this.cache[key] = vnode
}
vnode.data.keepAlive = true
}
return vnode
},
destroyed () {
for (const key in this.cache) {
const vnode = this.cache[key]
callHook(vnode.child, 'deactivated')
vnode.child.$destroy()
}
}
}

最新文章

  1. doT.js学习
  2. 二次、三次贝塞尔曲线demo(演示+获取坐标点)
  3. hadoop源码编译——2.5.0版本
  4. mysql的卸载方法
  5. ae 打开地图文档
  6. [ionic开源项目教程] - 手把手教你使用移动跨平台开发框架Ionic开发一个新闻阅读APP
  7. 51nod 博弈论水题
  8. 奥运会订票系统c语言代写源码下载
  9. Hadoop初步认识
  10. C语言位运算符:与、或、异或、取反,左移和右移
  11. hasLayout与Block formatting contexts的学习(下)
  12. 轮值CEO胡厚崑:到2025年所有的企业都将用到云(云的2.0时代,会有几千朵云几万朵云升起来,这将产生不同的技术模式、商业模式、思维模式)
  13. activity的生命周期详解
  14. Linux系统常见调用及其分类
  15. Java 多线程系列 CountDownLatch
  16. Ubuntu上部署tomcat后无法访问8080端口问题
  17. [转帖]2015年时微软Win3.1崩溃迫使巴黎奥利机场短暂关闭
  18. 谁在用 Hadoop
  19. nodejs——发送邮件(带附件)
  20. SpringCloud之Eureka 服务注册和服务发现基础篇2

热门文章

  1. python 面向对象 公有属性 用在哪里
  2. (转)利用Spring AOP自定义注解解决日志和签名校验
  3. TabControl delphi
  4. 162. Find Peak Element(二分查找 )
  5. uva1401 dp+Trie
  6. 使用老毛桃安装Windows操作系统
  7. centos配置用户级别的jdk的环境变量
  8. Qt的信号和槽是如何工作的
  9. c++第二十五天
  10. linux history记录格式修改