Skip to content

Commit

Permalink
version 3.2.1-beta.1
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmak1 committed Nov 7, 2024
1 parent e414a80 commit 29a38fe
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 21 deletions.
Binary file added .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cample",
"version": "3.2.0-alpha.49",
"version": "3.2.1-beta.1",
"description": "Cample.js - one of the fastest frameworks without a virtual DOM on the Internet!",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
Binary file added src/.DS_Store
Binary file not shown.
63 changes: 44 additions & 19 deletions src/core/components/each/each.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
checkObject,
cloneValue,
getKey,
swapElements,
swapElements1,
swapElements2,
getDataFunctions
} from "../../../shared/utils";
import {
Expand Down Expand Up @@ -239,6 +240,7 @@ export class Each extends DataComponent {
nodeNext = document.createComment("");
parentNode.appendChild(nodeNext);
}
currentComponent.nodes = new Array(newDataLength);
if (this.isIteration) {
for (let i = 0; i < newDataLength; i++) {
const indexData = data[i];
Expand All @@ -254,7 +256,7 @@ export class Each extends DataComponent {
importData,
newKey
);
currentComponent.nodes.push(currentNode);
currentComponent.nodes[i] = currentNode;
parentNode.insertBefore(el, nodeNext);
}
} else {
Expand All @@ -271,7 +273,7 @@ export class Each extends DataComponent {
importData,
newKey
);
currentComponent.nodes.push(currentNode);
currentComponent.nodes[i] = currentNode;
parentNode.insertBefore(el, nodeNext);
}
}
Expand Down Expand Up @@ -365,13 +367,18 @@ export class Each extends DataComponent {
importData,
oldData
);
const elNext = newData[currentNewLastIndex + 1];
const el1 = (newData[newFirstIndex] =
oldNodes[currentOldLastIndex]).el as Element;
const el2 = (newData[currentNewLastIndex] =
oldNodes[oldFirstIndex++]).el as Element;
el1[EACH_INDEX_NAME] = newFirstIndex++;
el2[EACH_INDEX_NAME] = currentNewLastIndex;
swapElements(el1, el2, parentNode);
if (elNext) {
swapElements1(el1, el2, elNext.el, parentNode);
} else {
swapElements2(el1, el2, parentNode);
}
newLastIndex--;
oldLastIndex--;
continue;
Expand Down Expand Up @@ -421,14 +428,19 @@ export class Each extends DataComponent {
(nodeNext as ChildNode).remove();
}
} else if (isRemove) {
for (
let i = oldFirstIndex;
oldFirstIndex < oldLastIndex--;
i++
) {
const currentNode = oldNodes[i];
const { el } = currentNode;
(el as ChildNode).remove();
if (oldLastIndex - oldFirstIndex === 1) {
const currentNode = oldNodes[oldFirstIndex].el;
(currentNode as ChildNode).remove();
} else {
for (
let i = oldFirstIndex;
oldFirstIndex < oldLastIndex--;
i++
) {
const currentNode = oldNodes[i];
const { el } = currentNode;
(el as ChildNode).remove();
}
}
} else {
const indexesOldArr = {};
Expand Down Expand Up @@ -533,13 +545,18 @@ export class Each extends DataComponent {
importData,
oldData
);
const elNext = newData[currentNewLastIndex + 1];
const el1 = (newData[newFirstIndex] =
oldNodes[currentOldLastIndex]).el as Element;
const el2 = (newData[currentNewLastIndex] =
oldNodes[oldFirstIndex++]).el as Element;
el1[EACH_INDEX_NAME] = newFirstIndex++;
el2[EACH_INDEX_NAME] = currentNewLastIndex;
swapElements(el1, el2, parentNode);
if (elNext) {
swapElements1(el1, el2, elNext.el, parentNode);
} else {
swapElements2(el1, el2, parentNode);
}
newLastIndex--;
oldLastIndex--;
continue;
Expand Down Expand Up @@ -621,16 +638,24 @@ export class Each extends DataComponent {
(nodeNext as ChildNode).remove();
}
} else {
for (
let i = oldFirstIndex;
oldFirstIndex < oldLastIndex--;
i++
) {
const currentNode = oldNodes[i];
if (oldLastIndex - oldFirstIndex === 1) {
const currentNode = oldNodes[oldFirstIndex];
if (currentNode !== undefined) {
const { el } = currentNode;
(el as ChildNode).remove();
}
} else {
for (
let i = oldFirstIndex;
oldFirstIndex < oldLastIndex--;
i++
) {
const currentNode = oldNodes[i];
if (currentNode !== undefined) {
const { el } = currentNode;
(el as ChildNode).remove();
}
}
}
}
}
Expand Down
13 changes: 12 additions & 1 deletion src/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,25 @@ export const cloneTemplate = (obj1: TemplateExportValueType) => {
return newObj;
};

export const swapElements = (
export const swapElements1 = (
el1: Element,
el2: Element,
el3: Element,
parentNode: ParentNode
) => {
parentNode.insertBefore(el1, el2);
parentNode.insertBefore(el2, el3);
};

export const swapElements2 = (
el1: Element,
el2: Element,
parentNode: ParentNode
) => {
const nextEl1 = el1.nextSibling;
parentNode.insertBefore(parentNode.replaceChild(el1, el2), nextEl1);
};

export const getAttrKeys = (
el: Element
): [ArrayStringType, ArrayStringType] => {
Expand Down

0 comments on commit 29a38fe

Please sign in to comment.