@@ -51,85 +51,12 @@ function ready () {
5151}
5252
5353/**
54- * Teardown an instance, unobserves the data, unbind all the
55- * directives, turn off all the event listeners, etc.
56- *
57- * @param {Boolean } remove - whether to remove the DOM node.
58- * @param {Boolean } deferCleanup - if true, defer cleanup to
59- * be called later
60- * @public
54+ * Teardown the instance, simply delegate to the internal
55+ * _destroy.
6156 */
6257
6358exports . $destroy = function ( remove , deferCleanup ) {
64- if ( this . _isBeingDestroyed ) {
65- return
66- }
67- this . _callHook ( 'beforeDestroy' )
68- this . _isBeingDestroyed = true
69- var i
70- // remove self from parent. only necessary
71- // if parent is not being destroyed as well.
72- var parent = this . $parent
73- if ( parent && ! parent . _isBeingDestroyed ) {
74- i = parent . _children . indexOf ( this )
75- parent . _children . splice ( i , 1 )
76- }
77- // destroy all children.
78- if ( this . _children ) {
79- i = this . _children . length
80- while ( i -- ) {
81- this . _children [ i ] . $destroy ( )
82- }
83- }
84- // teardown all directives. this also tearsdown all
85- // directive-owned watchers. intentionally check for
86- // directives array length on every loop since directives
87- // that manages partial compilation can splice ones out
88- for ( i = 0 ; i < this . _directives . length ; i ++ ) {
89- this . _directives [ i ] . _teardown ( )
90- }
91- // teardown all user watchers.
92- for ( i in this . _userWatchers ) {
93- this . _userWatchers [ i ] . teardown ( )
94- }
95- // remove reference to self on $el
96- if ( this . $el ) {
97- this . $el . __vue__ = null
98- }
99- // remove DOM element
100- var self = this
101- if ( remove && this . $el ) {
102- this . $remove ( function ( ) {
103- self . _cleanup ( )
104- } )
105- } else if ( ! deferCleanup ) {
106- this . _cleanup ( )
107- }
108- }
109-
110- /**
111- * Clean up to ensure garbage collection.
112- * This is called after the leave transition if there
113- * is any.
114- */
115-
116- exports . _cleanup = function ( ) {
117- // remove reference from data ob
118- this . _data . __ob__ . removeVm ( this )
119- this . _data =
120- this . _watchers =
121- this . _userWatchers =
122- this . _watcherList =
123- this . $el =
124- this . $parent =
125- this . $root =
126- this . _children =
127- this . _directives = null
128- // call the last hook...
129- this . _isDestroyed = true
130- this . _callHook ( 'destroyed' )
131- // turn off all instance listeners.
132- this . $off ( )
59+ this . _destroy ( remove , deferCleanup )
13360}
13461
13562/**
0 commit comments