Skip to content

Commit

Permalink
[fix] 2 detail bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
TechQuery committed Feb 7, 2024
1 parent 22c9f33 commit dce1e63
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 22 deletions.
4 changes: 0 additions & 4 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
#!/bin/sh

. "$(dirname "$0")/_/husky.sh"

npm test
4 changes: 0 additions & 4 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
#!/bin/sh

. "$(dirname "$0")/_/husky.sh"

npm run build
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dom-renderer",
"version": "2.1.0",
"version": "2.1.1",
"license": "LGPL-3.0-or-later",
"author": "shiy2008@gmail.com",
"description": "A light-weight DOM Renderer supports Web components standard & TypeScript language",
Expand Down Expand Up @@ -30,7 +30,7 @@
"devDependencies": {
"@types/jest": "^29.5.12",
"@types/node": "^18.19.14",
"husky": "^8.0.3",
"husky": "^9.0.10",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"lint-staged": "^15.2.2",
Expand All @@ -56,7 +56,7 @@
},
"browserslist": "> 0.5%, last 2 versions, not dead, IE 11",
"scripts": {
"prepare": "husky install",
"prepare": "husky",
"test": "lint-staged && jest",
"parcel": "tsc -p tsconfig.json && mv dist/jsx-runtime.* . && cp jsx-runtime.js jsx-dev-runtime.js && mv dist/dist/* dist/ && rm -rf dist/dist",
"build": "rm -rf dist/ docs/ && typedoc && npm run parcel",
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

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

6 changes: 2 additions & 4 deletions source/dist/DOMRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,8 @@ export class DOMRenderer {
for (const oldNode of [...root.childNodes]) {
const index = newNodes.indexOf(oldNode);

if (index < 0) {
oldNode.remove();
continue;
} else if (index === 0) {
if (index < 0) continue;
else if (index === 0) {
newNodes.shift();
continue;
}
Expand Down
6 changes: 4 additions & 2 deletions test/DOMRenderer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,19 @@ describe('DOM Renderer', () => {
});

it('should update DOM children without keys', () => {
const newNode = renderer.patch(
var newNode = renderer.patch(
{ ...root },
{ ...root, children: [{ children: [new VNode({ tagName: 'i' })] }] }
);
expect(document.body.innerHTML).toBe('<i></i>');

renderer.patch(newNode, {
newNode = renderer.patch(newNode, {
...root,
children: [{ children: [new VNode({ tagName: 'a' })] }]
});
expect(document.body.innerHTML).toBe('<a></a>');

renderer.patch(newNode, root);
});

it('should not invoke duplicated Connected Callbacks during updating', () => {
Expand Down

0 comments on commit dce1e63

Please sign in to comment.