Skip to content
This repository was archived by the owner on May 5, 2021. It is now read-only.

Commit 04fcb7e

Browse files
committed
perf for attributes + instanceof
1 parent 20be678 commit 04fcb7e

File tree

31 files changed

+162
-66
lines changed

31 files changed

+162
-66
lines changed

packages/plugin-blockquote/src/BlockquoteXmlDomParser.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ export class BlockquoteXmlDomParser extends AbstractParser<Node> {
1313

1414
async parse(item: Element): Promise<BlockquoteNode[]> {
1515
const blockquote = new BlockquoteNode();
16-
blockquote.modifiers.append(this.engine.parseAttributes(item));
16+
const attributes = this.engine.parseAttributes(item);
17+
if (attributes.length) {
18+
blockquote.modifiers.append(attributes);
19+
}
1720
const nodes = await this.engine.parse(...item.childNodes);
1821
blockquote.append(...nodes);
1922
return [blockquote];

packages/plugin-bold/src/BoldXmlDomParser.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ export class BoldXmlDomParser extends FormatXmlDomParser {
1515
*/
1616
async parse(item: Element): Promise<VNode[]> {
1717
const bold = new BoldFormat(nodeName(item) as 'B' | 'STRONG');
18-
bold.modifiers.append(this.engine.parseAttributes(item));
18+
const attributes = this.engine.parseAttributes(item);
19+
if (attributes.length) {
20+
bold.modifiers.append(attributes);
21+
}
1922
const children = await this.engine.parse(...item.childNodes);
2023
this.applyFormat(bold, children);
2124

packages/plugin-divider/src/DividerXmlDomParser.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ export class DividerXmlDomParser extends AbstractParser<Node> {
1313

1414
async parse(item: Element): Promise<DividerNode[]> {
1515
const divider = new DividerNode();
16-
divider.modifiers.append(this.engine.parseAttributes(item));
16+
const attributes = this.engine.parseAttributes(item);
17+
if (attributes.length) {
18+
divider.modifiers.append(attributes);
19+
}
1720

1821
const nodes = await this.engine.parse(...item.childNodes);
1922
divider.append(...nodes);

packages/plugin-heading/src/HeadingXmlDomParser.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ export class HeadingXmlDomParser extends AbstractParser<Node> {
1515

1616
async parse(item: Element): Promise<HeadingNode[]> {
1717
const heading = new HeadingNode({ level: parseInt(nodeName(item)[1], 10) });
18-
heading.modifiers.append(this.engine.parseAttributes(item));
18+
const attributes = this.engine.parseAttributes(item);
19+
if (attributes.length) {
20+
heading.modifiers.append(attributes);
21+
}
1922
const nodes = await this.engine.parse(...item.childNodes);
2023
heading.append(...nodes);
2124
return [heading];

packages/plugin-input/src/InputXmlDomParser.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ export class InputXmlDomParser extends AbstractParser<Node> {
1818
name: item.getAttribute('name'),
1919
value: item.value,
2020
});
21-
input.modifiers.append(this.engine.parseAttributes(item));
22-
const attributes = input.modifiers.find(Attributes);
21+
const attributes = this.engine.parseAttributes(item);
2322
if (attributes) {
2423
attributes.remove('type'); // type is on input.inputType
2524
attributes.remove('name'); // type is on input.inputName
2625
}
26+
if (attributes.length) {
27+
input.modifiers.append(attributes);
28+
}
2729
const nodes = await this.engine.parse(...item.childNodes);
2830
input.append(...nodes);
2931
return [input];

packages/plugin-italic/src/ItalicXmlDomParser.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ export class ItalicXmlDomParser extends FormatXmlDomParser {
1515
*/
1616
async parse(item: Element): Promise<VNode[]> {
1717
const italic = new ItalicFormat(nodeName(item) as 'I' | 'EM');
18-
italic.modifiers.append(this.engine.parseAttributes(item));
18+
const attributes = this.engine.parseAttributes(item);
19+
if (attributes.length) {
20+
italic.modifiers.append(attributes);
21+
}
1922
const children = await this.engine.parse(...item.childNodes);
2023
this.applyFormat(italic, children);
2124

packages/plugin-linebreak/src/LineBreakXmlDomParser.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ export class LineBreakXmlDomParser extends AbstractParser<Node> {
1717
return [];
1818
}
1919
const lineBreak = new LineBreakNode();
20-
lineBreak.modifiers.append(this.engine.parseAttributes(item));
20+
const attributes = this.engine.parseAttributes(item);
21+
if (attributes.length) {
22+
lineBreak.modifiers.append(attributes);
23+
}
2124
return [lineBreak];
2225
}
2326

packages/plugin-link/src/LinkFormat.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ export class LinkFormat extends Format {
2222
}
2323

2424
get target(): string {
25-
return this.modifiers.find(Attributes)?.get('target');
25+
return this.modifiers.find(Attributes)?.get('target') || '';
2626
}
2727

28-
set target(url: string) {
29-
this.modifiers.get(Attributes).set('target', url);
28+
set target(target: string) {
29+
if (target.length) {
30+
this.modifiers.get(Attributes).set('target', target);
31+
}
3032
}
3133

3234
//--------------------------------------------------------------------------

packages/plugin-link/src/LinkXmlDomParser.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ export class LinkXmlDomParser extends FormatXmlDomParser {
1313
const link = new LinkFormat(item.getAttribute('href'));
1414
// TODO: Link should not have an `Attributes` modifier outside of XML.
1515
// In XML context we need to conserve the order of attributes.
16-
link.modifiers.replace(Attributes, this.engine.parseAttributes(item));
16+
const attributes = this.engine.parseAttributes(item);
17+
if (attributes.length) {
18+
link.modifiers.replace(Attributes, attributes);
19+
}
1720
const children = await this.engine.parse(...item.childNodes);
1821
this.applyFormat(link, children);
1922

packages/plugin-link/src/components/LinkComponent.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import { OwlComponent } from '../../../plugin-owl/src/OwlComponent';
2-
import { InlineNode } from '../../../plugin-inline/src/InlineNode';
3-
import { LinkFormat } from '../LinkFormat';
42
import { LinkParams } from '../Link';
53
import { Layout } from '../../../plugin-layout/src/Layout';
64
import { useState } from '@odoo/owl';

0 commit comments

Comments
 (0)