@@ -47,13 +47,13 @@ module.exports = window;
4747 * @param {Array } children - The virtual DOM children
4848 * @return {VDom } Returns the VDom element
4949 */
50- let createElement = ( element , props = { } , ...children ) => (
50+ let createElement = ( element , props , ...children ) => (
5151 {
5252
5353 $ : element , // "$" holds the name or function passed as
5454 // first argument
5555
56- a : ( ! props || props . $ || props . concat || props . toFixed ) // If the props argument is false/null, a renderable
56+ a : ( ! props || props . $ || props . concat || props . toFixed ) // If the props argument is false/null/0 , a renderable
5757 // VNode, a string, an array (.concat exists on both
5858 // strings and arrays), or a number ...
5959
@@ -151,7 +151,7 @@ module.exports = window;
151151 updateDom = ( node , vnode , hooks ) => (
152152 vnode . $
153153 ? Object . keys ( vnode . a ) . map ( // - Element nodes have properties
154- ( key ) => // 1. The property name
154+ ( key ) =>
155155 key == "style" ? // The "style" property is an object and must be
156156 // applied recursively.
157157 Object . assign (
@@ -160,7 +160,7 @@ module.exports = window;
160160 )
161161
162162 : ( node [ key ] == vnode . a [ key ] // All properties are applied directly to DOM, as
163- ? node : ( node [ key ] = vnode . a [ key ] ) ) // long as they are different than ther value in the
163+ ? node : ( node [ key ] = vnode . a [ key ] ) ) // long as they are different than their value in the
164164 // instance. This includes `onXXX` event handlers.
165165
166166 ) &&
@@ -176,8 +176,8 @@ module.exports = window;
176176 vnode . a . c , // we recursively continue rendering into it"s
177177 node // child nodes.
178178 ) )
179- : ( node . data == vnode ) // - String nodes update only the text content is changed
180- ? node : ( node . data = vnode ) ,
179+ : ( node . data == vnode ) // - String nodes update only if the text content
180+ ? node : ( node . data = vnode ) , // has changed.
181181 Object . assign ( node , hooks ) ,
182182 _new_cache [ hooks . k ] = node
183183 ) ,
@@ -215,33 +215,36 @@ module.exports = window;
215215 } ,
216216
217217 _xvnode = expandStateful ( // Recursively expand the stateful component functions until
218- vnode , // we have reached the
218+ vnode , // we have reached a VDom child.
219219 _hooks
220220 )
221221
222222 ) =>
223- callLifecycleMethods (
224- updateDom (
225- // (We are recycling the no-longer used `vnode` property
226- // as a compression optimization)
227- ( vnode = // Keep track of the node we just added because we will need
223+ // Note that the following set of actions happen in reverse:
224+ callLifecycleMethods ( // 3. Call-out to the appropriate lifecycle method
225+ updateDom ( // 2. Update the DOM properties
226+ // (We are recycling the no-longer used `vnode`
227+ // property as a compression optimization) // 1. Create a new and replace, or re-use previous DOM element:
228+ //
229+ ( vnode = // (Keep track of the node we just added because we will need
228230 // it for the next iteration and for the last part of the
229- // current function call.
231+ // current function call)
230232
231- ( ( ( dom . childNodes [ idx ] || _xvnode ) . k ) != _key ) // previous node should be the expected.
233+ ( ( ( dom . childNodes [ idx ] || _xvnode ) . k ) != _key ) // If the nodes appear in the expected order, do not perform
234+ // any DOM re-ordering.
232235 ? dom . insertBefore ( // a. If the node should be re-ordered, place it right after
233236 _prevnode || // the last known item.
234237 ( _xvnode . $
235238 ? document . createElement ( _xvnode . $ )
236239 : document . createTextNode ( _xvnode ) ) ,
237240 dom . childNodes [ idx ]
238241 )
239- : _prevnode // b. Otherwise keep the reference
242+ : _prevnode // b. Otherwise keep the previous reference
240243 ) ,
241- _xvnode ,
244+ _xvnode , // Arguments to `updateDom`
242245 _hooks
243- ) == _prevnode
244- ? _hooks . d // .d - Update if it"s an old node
246+ ) == _prevnode // If the node we just updated was the previous node,
247+ ? _hooks . d // .d - Call the update lifecycle method
245248 : _hooks . m , // .m - Otherwise this is a new node, call mount
246249 vnode
247250 )
0 commit comments