Skip to content

Commit

Permalink
feat: ignore and replace flags
Browse files Browse the repository at this point in the history
  • Loading branch information
aidenybai committed Nov 1, 2021
1 parent b0f9525 commit 36710da
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 33 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"@types/glob": "^7.2.0",
"@types/jest": "^27.0.2",
"@types/node": "^16.11.6",
"@typescript-eslint/eslint-plugin": "^5.2.0",
"@typescript-eslint/eslint-plugin": "^5.3.0",
"@typescript-eslint/parser": "^4.33.0",
"benchmark": "^2.1.4",
"eslint": "^8.1.0",
Expand Down
48 changes: 24 additions & 24 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 0 additions & 7 deletions src/__test__/patch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,4 @@ describe('.patch', () => {

expect(el2).toEqual(document.createElement('a'));
});

it('should return el if ignore is set', () => {
const el1 = createElement(m('div', { ignore: true }));
const el2 = patch(el1, m('a'));

expect(el2).toEqual(el1);
});
});
7 changes: 7 additions & 0 deletions src/drivers/children.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ export const childrenDriver =
workStack,
};

if (newVNode.flag === VFlags.IGNORE_NODE) return data;

if (newVNode.flag === VFlags.REPLACE_NODE) {
el.replaceWith(createElement(newVNode));
return data;
}

const oldVNodeChildren: VNode[] = oldVNode?.children ?? [];
const newVNodeChildren: VNode[] | undefined = newVNode.children;
const delta: VDelta | undefined = newVNode.delta;
Expand Down
1 change: 0 additions & 1 deletion src/patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export const compose =
if (!hasString) {
const oldVElement = <VElement>prevVNode;
const newVElement = <VElement>newVNode;
if (oldVElement?.props?.ignore || newVElement?.props?.ignore) return finish(el);
if (
(oldVElement?.key === undefined && newVElement?.key === undefined) ||
oldVElement?.key !== newVElement?.key
Expand Down
2 changes: 2 additions & 0 deletions src/types/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export enum VFlags {
ONLY_TEXT_CHILDREN = 1,
ONLY_KEYED_CHILDREN = 2,
ANY_CHILDREN = 3,
REPLACE_NODE = 4,
IGNORE_NODE = 5,
}

export const enum VDeltaOperationTypes {
Expand Down

0 comments on commit 36710da

Please sign in to comment.