@@ -8,9 +8,9 @@ import computeExpression from '@utils/computeExpression';
8
8
import { expressionPropRE , parenthesisWrapReplaceRE } from '@utils/patterns' ;
9
9
10
10
// This directive is size-based, not content-based, since everything is compiled and rerendered
11
+ // It's also quite expensive on performance, and should be refactored in the future
11
12
export const forDirective = ( { el, data, state, node } : DirectiveProps ) : void => {
12
13
const originalAST = el [ COMPONENT_FLAG ] ;
13
- // Initial compilation
14
14
if ( ! originalAST ) el [ COMPONENT_FLAG ] = compile ( el , state ) ;
15
15
16
16
const forLoopRE = / \s + (?: i n | o f ) \s + / gim;
@@ -24,15 +24,17 @@ export const forDirective = ({ el, data, state, node }: DirectiveProps): void =>
24
24
const template = el [ FOR_TEMPLATE_FLAG ] ;
25
25
if ( el . innerHTML . trim ( ) === template ) el . innerHTML = '' ;
26
26
27
+ // This just checks if there is deviation from both (removal/addition/nochange)
27
28
const arrayDiff = currArray ?. length - el . children . length ;
29
+ const tableElementRE = / ^ [ ^ \S ] * ?< ( t (?: h e a d | b o d y | f o o t | r | d | h ) ) / i;
28
30
29
31
if ( currArray ?. length === 0 ) el . innerHTML = '' ;
30
32
else if ( arrayDiff !== 0 ) {
31
33
for ( let i = Math . abs ( arrayDiff ) ; i > 0 ; -- i ) {
32
34
if ( arrayDiff < 0 ) el . removeChild ( el . lastChild as Node ) ;
33
35
else {
34
36
let content = String ( template ) ;
35
- const isTable = / ^ [ ^ \S ] * ? < ( t (?: h e a d | b o d y | f o o t | r | d | h ) ) / i . test ( content ) ;
37
+ const isTable = tableElementRE . test ( content ) ;
36
38
37
39
/* istanbul ignore next */
38
40
if ( item ) {
0 commit comments