|
|
@@ -50,46 +50,81 @@ module.exports = {
|
|
|
// NOTE: this function is shared in v-partial
|
|
|
compile: function (frag) {
|
|
|
var vm = this.vm
|
|
|
- var originalChildLength = vm._children.length
|
|
|
- var originalParentChildLength = vm.$parent &&
|
|
|
- vm.$parent._children.length
|
|
|
// the linker is not guaranteed to be present because
|
|
|
// this function might get called by v-partial
|
|
|
this.unlink = this.linker
|
|
|
? this.linker(vm, frag)
|
|
|
: vm.$compile(frag)
|
|
|
transition.blockAppend(frag, this.end, vm)
|
|
|
- this.children = vm._children.slice(originalChildLength)
|
|
|
- if (vm.$parent) {
|
|
|
- this.children = this.children.concat(
|
|
|
- vm.$parent._children.slice(originalParentChildLength)
|
|
|
- )
|
|
|
- }
|
|
|
- if (this.children.length && _.inDoc(vm.$el)) {
|
|
|
- this.children.forEach(function (child) {
|
|
|
- child._callHook('attached')
|
|
|
- })
|
|
|
+ // call attached for all the child components created
|
|
|
+ // during the compilation
|
|
|
+ if (_.inDoc(vm.$el)) {
|
|
|
+ var children = this.getContainedComponents()
|
|
|
+ if (children) children.forEach(callAttach)
|
|
|
}
|
|
|
},
|
|
|
|
|
|
// NOTE: this function is shared in v-partial
|
|
|
teardown: function () {
|
|
|
if (!this.unlink) return
|
|
|
- transition.blockRemove(this.start, this.end, this.vm)
|
|
|
- if (this.children && _.inDoc(this.vm.$el)) {
|
|
|
- this.children.forEach(function (child) {
|
|
|
- if (!child._isDestroyed) {
|
|
|
- child._callHook('detached')
|
|
|
- }
|
|
|
- })
|
|
|
+ // collect children beforehand
|
|
|
+ var children
|
|
|
+ if (_.inDoc(this.vm.$el)) {
|
|
|
+ children = this.getContainedComponents()
|
|
|
}
|
|
|
+ transition.blockRemove(this.start, this.end, this.vm)
|
|
|
+ if (children) children.forEach(callDetach)
|
|
|
this.unlink()
|
|
|
this.unlink = null
|
|
|
},
|
|
|
|
|
|
+ // NOTE: this function is shared in v-partial
|
|
|
+ getContainedComponents: function () {
|
|
|
+ var vm = this.vm
|
|
|
+ var start = this.start.nextSibling
|
|
|
+ var end = this.end
|
|
|
+ var selfCompoents =
|
|
|
+ vm._children.length &&
|
|
|
+ vm._children.filter(contains)
|
|
|
+ var transComponents =
|
|
|
+ vm._transCpnts &&
|
|
|
+ vm._transCpnts.filter(contains)
|
|
|
+
|
|
|
+ function contains (c) {
|
|
|
+ var cur = start
|
|
|
+ var next
|
|
|
+ while (next !== end) {
|
|
|
+ next = cur.nextSibling
|
|
|
+ if (cur.contains(c.$el)) {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ cur = next
|
|
|
+ }
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
+ return selfCompoents
|
|
|
+ ? transComponents
|
|
|
+ ? selfCompoents.concat(transComponents)
|
|
|
+ : selfCompoents
|
|
|
+ : transComponents
|
|
|
+ },
|
|
|
+
|
|
|
// NOTE: this function is shared in v-partial
|
|
|
unbind: function () {
|
|
|
if (this.unlink) this.unlink()
|
|
|
}
|
|
|
|
|
|
+}
|
|
|
+
|
|
|
+function callAttach (child) {
|
|
|
+ if (!child._isAttached) {
|
|
|
+ child._callHook('attached')
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function callDetach (child) {
|
|
|
+ if (child._isAttached) {
|
|
|
+ child._callHook('detached')
|
|
|
+ }
|
|
|
}
|