mirror of https://github.com/vuejs/vue.git
				
				
				
			child VMs should remove itself from parent's $ when destroyed
This commit is contained in:
		
							parent
							
								
									d191ce3062
								
							
						
					
					
						commit
						be72b739c5
					
				| 
						 | 
				
			
			@ -78,6 +78,7 @@ function Compiler (vm, options) {
 | 
			
		|||
    // register child id on parent
 | 
			
		||||
    var childId = compiler.el.getAttribute(idAttr)
 | 
			
		||||
    if (childId && parent) {
 | 
			
		||||
        compiler.childId = childId
 | 
			
		||||
        parent.vm.$[childId] = vm
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -590,9 +591,13 @@ CompilerProto.destroy = function () {
 | 
			
		|||
        }
 | 
			
		||||
    }
 | 
			
		||||
    // remove self from parentCompiler
 | 
			
		||||
    var parent = compiler.parentCompiler
 | 
			
		||||
    var parent = compiler.parentCompiler,
 | 
			
		||||
        childId = compiler.childId
 | 
			
		||||
    if (parent) {
 | 
			
		||||
        parent.childCompilers.splice(parent.childCompilers.indexOf(compiler), 1)
 | 
			
		||||
        if (childId) {
 | 
			
		||||
            delete parent.vm.$[childId]
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    // remove el
 | 
			
		||||
    if (el === document.body) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,32 +0,0 @@
 | 
			
		|||
<!DOCTYPE html>
 | 
			
		||||
<html lang="en">
 | 
			
		||||
    <head>
 | 
			
		||||
        <title></title>
 | 
			
		||||
        <meta charset="utf-8">
 | 
			
		||||
        <script src="../../../dist/seed.js"></script>
 | 
			
		||||
    </head>
 | 
			
		||||
    <body>
 | 
			
		||||
        <div id="parent">
 | 
			
		||||
            <div sd-id="child" sd-viewmodel="child">
 | 
			
		||||
                {{msg}}
 | 
			
		||||
            </div>
 | 
			
		||||
        </div>
 | 
			
		||||
        <script>
 | 
			
		||||
            Seed.viewmodel('child', Seed.extend({
 | 
			
		||||
                init: function () {
 | 
			
		||||
                    console.log('child init!')
 | 
			
		||||
                },
 | 
			
		||||
                proto: {
 | 
			
		||||
                    hi: function () {
 | 
			
		||||
                        console.log('hi from child!')
 | 
			
		||||
                    }
 | 
			
		||||
                },
 | 
			
		||||
                scope: {
 | 
			
		||||
                    msg: 'I am a child'
 | 
			
		||||
                }
 | 
			
		||||
            }))
 | 
			
		||||
            var app = new Seed({el:'#parent'})
 | 
			
		||||
            app.$.child.msg = 'Set from the parent!'
 | 
			
		||||
        </script>
 | 
			
		||||
    </body>
 | 
			
		||||
</html>
 | 
			
		||||
| 
						 | 
				
			
			@ -566,6 +566,8 @@ describe('UNIT: Directives', function () {
 | 
			
		|||
            assert.ok(t.$.hihi instanceof Child)
 | 
			
		||||
            t.$.hihi.test()
 | 
			
		||||
            assert.ok(called)
 | 
			
		||||
            t.$.hihi.$destroy()
 | 
			
		||||
            assert.notOk('hihi' in t.$)
 | 
			
		||||
        })
 | 
			
		||||
 | 
			
		||||
    })
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue