Skip to content

Commit

Permalink
Introduce a claim_space helper
Browse files Browse the repository at this point in the history
This brings the hydration `claim` code more in-line with what the
`create` code does.
  • Loading branch information
Swatinem committed Sep 6, 2019
1 parent cc10714 commit fe8ca05
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/compiler/compile/render_dom/wrappers/Text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,12 @@ export default class TextWrapper extends Wrapper {

render(block: Block, parent_node: string, parent_nodes: string) {
if (this.skip) return;
const use_space = this.use_space();

block.add_element(
this.var,
this.use_space() ? `@space()` : `@text(${stringify(this.data)})`,
parent_nodes && `@claim_text(${parent_nodes}, ${stringify(this.data)})`,
use_space ? `@space()` : `@text(${stringify(this.data)})`,
parent_nodes && (use_space ? `@claim_space(${parent_nodes})` : `@claim_text(${parent_nodes}, ${stringify(this.data)})`),
parent_node
);
}
Expand Down
4 changes: 4 additions & 0 deletions src/runtime/internal/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ export function claim_text(nodes, data) {
return text(data);
}

export function claim_space(nodes) {
return claim_text(nodes, ' ');
}

export function set_data(text, data) {
data = '' + data;
if (text.data !== data) text.data = data;
Expand Down

0 comments on commit fe8ca05

Please sign in to comment.