@@ -22,7 +22,7 @@ const checkDestroyed = (state) => {
2222 if ( ! state . $ctx ) throw new Error ( '[EF] This component has been destroyed!' )
2323}
2424
25- const bindTextNode = ( ctx , { apply , node } ) => {
25+ const bindTextNode = ( ctx , node , apply ) => {
2626 // Data binding text node
2727 const textNode = DOM . document . createTextNode ( '' )
2828 const { dataNode, handlerNode, _key } = initBinding ( ctx , { bind : node } )
@@ -40,7 +40,7 @@ const bindTextNode = (ctx, {apply, node}) => {
4040 apply ( textNode )
4141}
4242
43- const updateMountNode = ( { ctx, key, value} ) => {
43+ const updateMountNode = ( ctx , key , value ) => {
4444 const { children} = ctx
4545 const child = children [ key ]
4646 const { anchor, node} = child
@@ -56,27 +56,27 @@ const updateMountNode = ({ctx, key, value}) => {
5656 }
5757 // Update stored value
5858 child . node = value
59- if ( value ) value . $mount ( { target : anchor , parent : ctx . state , option : mountOptions . BEFORE , key} )
59+ if ( value ) value . $mount ( { target : anchor , parent : ctx . state , option : mountOptions . AFTER , key} )
6060 exec ( )
6161}
6262
63- const updateMountList = ( { ctx, key, value} ) => {
63+ const updateMountList = ( ctx , key , value ) => {
6464 const { children} = ctx
6565 const { anchor, node} = children [ key ]
6666 if ( ARR . equals ( node , value ) ) return
6767 inform ( )
6868 if ( node . length ) node . clear ( )
6969 if ( value ) {
7070 value = ARR . copy ( value )
71- useFragment ( ( fragment , putBack ) => {
71+ useFragment ( ( fragment , recycleFragment ) => {
7272 // Update components
7373 for ( let item of value ) DOM . append ( fragment , shared . toEFComponent ( item ) . $mount ( { parent : ctx . state , key} ) )
7474 // Update stored value
7575 ARR . push ( node , ...value )
7676 // Append to current component
7777 queueDom ( ( ) => {
7878 DOM . after ( anchor , fragment )
79- putBack ( )
79+ recycleFragment ( )
8080 } )
8181 } )
8282 }
@@ -89,6 +89,7 @@ const mountPointUpdaters = [
8989]
9090
9191const applyMountPoint = ( type , key , tpl ) => {
92+ const updater = mountPointUpdaters [ type ]
9293 Object . defineProperty ( tpl . prototype , key , {
9394 get ( ) {
9495 if ( process . env . NODE_ENV !== 'production' ) checkDestroyed ( this )
@@ -97,24 +98,26 @@ const applyMountPoint = (type, key, tpl) => {
9798 set ( value ) {
9899 if ( process . env . NODE_ENV !== 'production' ) checkDestroyed ( this )
99100 const ctx = this . $ctx
100- mountPointUpdaters [ type ] ( { ctx, key, value} )
101+ updater ( ctx , key , value )
101102 } ,
102103 enumerable : true
103104 } )
104105}
105106
106- const bindMountNode = ( { ctx, key, anchor} ) => {
107+ const bindMountNode = ( ctx , key , anchor ) => {
107108 const { children } = ctx
108109 const info = { anchor}
109110 children [ key ] = info
110111 anchor [ EFMountPoint ] = info
111112}
112113
113- const bindMountList = ( { ctx, key, anchor} ) => {
114+ // eslint-disable-next-line max-params
115+ const bindMountList = ( ctx , key , anchor , aftAnchor ) => {
114116 const { children } = ctx
115117 children [ key ] = {
116- node : defineArr ( [ ] , { ctx, key, anchor} ) ,
117- anchor
118+ node : defineArr ( [ ] , { ctx, key, anchor, aftAnchor} ) ,
119+ anchor,
120+ aftAnchor
118121 }
119122 anchor [ EFMountPoint ] = children [ key ]
120123}
@@ -137,19 +140,23 @@ const resolveAST = (ctx, {apply, node, nodeType, namespace, create}) => {
137140 // Recursive call for child element
138141 if ( typeOf ( node [ 0 ] ) === 'object' ) apply ( create ( ctx , { node, namespace} ) )
139142 // Dynamic text node
140- else bindTextNode ( ctx , { apply , node } )
143+ else bindTextNode ( ctx , node , apply )
141144 break
142145 }
143146 // Mount points
144147 case 'object' : {
148+ if ( process . env . NODE_ENV !== 'production' ) apply ( DOM . document . createComment ( `<MountPoint${ node . t && ' type="list" ' || ' ' } name="${ node . n } ">` ) )
145149 const anchor = DOM . document . createTextNode ( '' )
146- // Single node mount point
147- if ( node . t === 0 ) bindMountNode ( { ctx, key : node . n , anchor} )
148- // Multi node mount point
149- else bindMountList ( { ctx, key : node . n , anchor} )
150150 // Append anchor
151- if ( process . env . NODE_ENV !== 'production' ) apply ( DOM . document . createComment ( `<MountPoint${ node . t && ' type="list" ' || ' ' } name="${ node . n } ">` ) )
152151 apply ( anchor )
152+ // Single node mount point
153+ if ( node . t === 0 ) bindMountNode ( ctx , node . n , anchor )
154+ else {
155+ // Multi node mount point
156+ const aftAnchor = DOM . document . createTextNode ( '' )
157+ apply ( aftAnchor )
158+ bindMountList ( ctx , node . n , anchor , aftAnchor )
159+ }
153160 if ( process . env . NODE_ENV !== 'production' ) apply ( DOM . document . createComment ( '</MountPoint>' ) )
154161 break
155162 }
@@ -211,7 +218,7 @@ const create = (ctx, {node, namespace}) => {
211218 if ( namespace === htmlNS ) namespace = ''
212219
213220 // First create an element according to the description
214- const [ element , type ] = createElement ( ctx , { info, namespace, fragment, custom} )
221+ const [ element , type ] = createElement ( ctx , info , namespace , fragment , custom )
215222
216223 let apply = noop
217224
0 commit comments