一般组件实例上的方法都是以 $ 开头的,比如 $watch、$emit、$update
但是销毁的方法却没有 $ 前缀,感觉用的时候会搞混
|
init: function(){}, |
|
config: function(){}, |
|
destroy: function(){ |
|
// destroy event wont propgation; |
|
this.$emit("$destroy"); |
|
this._watchers = null; |
|
this._watchersForStable = null; |
|
this.group && this.group.destroy(true); |
|
this.group = null; |
|
this.parentNode = null; |
|
this._children = null; |
|
this.$root = null; |
|
this._handles = null; |
|
this.$refs = null; |
|
var parent = this.$parent; |
|
if(parent && parent._children){ |
|
var index = parent._children.indexOf(this); |
|
parent._children.splice(index,1); |
|
} |
|
this.$parent = null; |
|
|
|
if (this.devtools) { |
|
this.devtools.emit("destroy", this) |
|
} |
|
this._handles = null; |
|
this.$phase = "destroyed"; |
|
}, |
这里的 destroy 和 config/init 应该是同样性质的,都是生命周期钩子,文档应该写在生命周期那个章节,但是同时它又会被当做方法来调用(比如在路由的场景下,组件不需要 cache 的话,就会主动 destroy)
https://regularjs.github.io/reference/
文档中的实例方法也没有提到 destroy,所以是不是可以考虑加个 $destroy 方法呢
一般组件实例上的方法都是以 $ 开头的,比如 $watch、$emit、$update
但是销毁的方法却没有 $ 前缀,感觉用的时候会搞混
regular/lib/render/client.js
Lines 315 to 341 in 6e18c7b
这里的 destroy 和 config/init 应该是同样性质的,都是生命周期钩子,文档应该写在生命周期那个章节,但是同时它又会被当做方法来调用(比如在路由的场景下,组件不需要 cache 的话,就会主动 destroy)
https://regularjs.github.io/reference/
文档中的实例方法也没有提到 destroy,所以是不是可以考虑加个 $destroy 方法呢