@@ -75,9 +75,9 @@ avalon.directive('widget', {
75
75
this . comVm = comVm
76
76
77
77
// ===创建组件的VM==END===
78
- var boss = avalon . scan ( component . template , comVm )
79
- comVm . $render = boss
80
- replaceRoot ( this , boss )
78
+ var innerRender = avalon . scan ( component . template , comVm )
79
+ comVm . $render = innerRender
80
+ replaceRoot ( this , innerRender )
81
81
var nodesWithSlot = [ ]
82
82
var directives = [ ]
83
83
if ( this . fragment || component . soleSlot ) {
@@ -87,11 +87,12 @@ avalon.directive('widget', {
87
87
nodesWithSlot = this . root . children
88
88
} )
89
89
directives = childBoss . directives
90
+ this . childBoss = childBoss
90
91
for ( var i in childBoss ) {
91
92
delete childBoss [ i ]
92
93
}
93
94
}
94
- boss . directives . push . apply ( boss . directives , directives )
95
+ Array . prototype . push . apply ( innerRender . directives , directives )
95
96
96
97
var arraySlot = [ ] ,
97
98
objectSlot = { }
@@ -120,16 +121,16 @@ avalon.directive('widget', {
120
121
}
121
122
//将原来元素的所有孩子,全部移动新的元素的第一个slot的位置上
122
123
if ( component . soleSlot ) {
123
- insertArraySlot ( boss . vnodes , arraySlot )
124
+ insertArraySlot ( innerRender . vnodes , arraySlot )
124
125
} else {
125
- insertObjectSlot ( boss . vnodes , objectSlot )
126
+ insertObjectSlot ( innerRender . vnodes , objectSlot )
126
127
}
127
128
}
128
129
129
130
if ( comment ) {
130
131
var dom = avalon . vdom ( vdom , 'toDOM' )
131
132
comment . parentNode . replaceChild ( dom , comment )
132
- comVm . $element = boss . root . dom = dom
133
+ comVm . $element = innerRender . root . dom = dom
133
134
delete this . reInit
134
135
}
135
136
@@ -141,24 +142,13 @@ avalon.directive('widget', {
141
142
} else {
142
143
fireComponentHook ( comVm , vdom , 'Ready' )
143
144
}
144
- this . beforeDispose = function ( ) {
145
- if ( ! this . cacheVm ) {
146
- fireComponentHook ( comVm , vdom , 'Dispose' )
147
- comVm . $hashcode = false
148
- delete avalon . vmodels [ comVm . $id ]
149
- this . boss . dispose ( )
150
- } else {
151
- fireComponentHook ( comVm , vdom , 'Leave' )
152
- }
153
-
154
- }
155
-
156
145
} ,
157
146
diff : function ( newVal , oldVal ) {
158
147
if ( cssDiff . call ( this , newVal , oldVal ) ) {
159
148
return true
160
149
}
161
150
} ,
151
+
162
152
update : function ( vdom , value ) {
163
153
this . oldValue = value //★★防止递归
164
154
switch ( this . readyState ) {
@@ -187,18 +177,29 @@ avalon.directive('widget', {
187
177
delete avalon . viewChanging
188
178
break
189
179
}
190
- }
180
+ } ,
181
+ beforeDispose : function ( ) {
182
+ var comVm = this . comVm
183
+ if ( ! this . cacheVm ) {
184
+ fireComponentHook ( comVm , this . node , 'Dispose' )
185
+ comVm . $hashcode = false
186
+ delete avalon . vmodels [ comVm . $id ]
187
+ this . innerRender && this . innerRender . dispose ( )
188
+ } else {
189
+ fireComponentHook ( comVm , this . node , 'Leave' )
190
+ }
191
+ } ,
191
192
} )
192
193
193
- function replaceRoot ( instance , boss ) {
194
- instance . boss = boss
195
- var root = boss . root
194
+ function replaceRoot ( instance , innerRender ) {
195
+ instance . innerRender = innerRender
196
+ var root = innerRender . root
196
197
var vdom = instance . node
197
198
for ( var i in root ) {
198
199
vdom [ i ] = root [ i ]
199
200
}
200
- boss . root = vdom
201
- boss . vnodes [ 0 ] = vdom
201
+ innerRender . root = vdom
202
+ innerRender . vnodes [ 0 ] = vdom
202
203
}
203
204
204
205
function fireComponentHook ( vm , vdom , name ) {
0 commit comments