Skip to content

Commit e414a80

Browse files
committed
version 3.2.1-beta.0
1 parent 97cb0a2 commit e414a80

File tree

8 files changed

+244
-80
lines changed

8 files changed

+244
-80
lines changed

src/core/components/each/each.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export class Each extends DataComponent {
7272
public importedDataName: string;
7373
public iteration: IterationFunctionType | undefined;
7474
public indexName: string;
75+
public stackName: string;
7576
public isDataFunction: boolean;
7677
public isIteration: boolean;
7778

@@ -91,12 +92,16 @@ export class Each extends DataComponent {
9192
: "importedData";
9293
this.iteration = options.iteration;
9394
this.indexName = options.indexName ? options.indexName : "index";
95+
this.stackName = options.stackName ? options.stackName : "stack";
9496
this.isDataFunction = checkFunction(data);
9597
this.isIteration = this.iteration !== undefined;
9698
if (
9799
this.indexName === this.valueName ||
98100
this.indexName === this.importedDataName ||
99-
this.valueName === this.importedDataName
101+
this.valueName === this.importedDataName ||
102+
this.stackName === this.importedDataName ||
103+
this.stackName === this.indexName ||
104+
this.stackName === this.valueName
100105
) {
101106
createError("Name error");
102107
}
@@ -868,16 +873,14 @@ export class Each extends DataComponent {
868873
[this.functionName]: this.valueName
869874
};
870875
const setDataFunctions = () => {
871-
if (this._isDataFunctions) {
872-
const objDataFunctions = getDataFunctions(dataFunction);
873-
renderFunctionsData(
874-
updateFunction,
875-
dataId,
876-
objDataFunctions,
877-
index,
878-
currentComponent
879-
);
880-
}
876+
const objDataFunctions = getDataFunctions(dataFunction);
877+
renderFunctionsData(
878+
updateFunction,
879+
dataId,
880+
objDataFunctions,
881+
index,
882+
currentComponent
883+
);
881884
};
882885

883886
const runRenderFunction = () => {
@@ -919,6 +922,7 @@ export class Each extends DataComponent {
919922
currentComponent.functions,
920923
this.valueName,
921924
this.importedDataName,
925+
this.stackName,
922926
this.indexName,
923927
true
924928
);

src/core/functions/data/create-each-dynamic-node-component.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import {
44
DynamicNodeComponentNodeType,
55
ElementsType,
66
ImportObjectType,
7-
EachTemplateType
7+
EachTemplateType,
8+
ClearStackType
89
} from "../../../types/types";
910

1011
export const createEachDynamicNodeComponentType = (
@@ -16,7 +17,7 @@ export const createEachDynamicNodeComponentType = (
1617
currentImport?: ImportObjectType,
1718
template?: EachTemplateType
1819
): EachDynamicNodeComponentType => {
19-
const DynamicNodeComponentType = {
20+
const DynamicNodeComponentType: any = {
2021
id: dataId,
2122
import: currentImport,
2223
elements,
@@ -27,7 +28,26 @@ export const createEachDynamicNodeComponentType = (
2728
nodeNext,
2829
template,
2930
keys: [],
30-
parentNode
31+
parentNode,
32+
eachStackValues: [],
33+
stack: []
3134
};
35+
const clearStack: ClearStackType = () => {
36+
if (DynamicNodeComponentType.stack.length > 0) {
37+
const { template } = DynamicNodeComponentType;
38+
const { eachStackValues } = template;
39+
for (let i = 0; i < DynamicNodeComponentType.stack.length; i++) {
40+
const currentActiveStack = DynamicNodeComponentType.stack[i];
41+
const currentNode = DynamicNodeComponentType.nodes[currentActiveStack];
42+
// So far for the main element. The logic used for values ​​will be done later, but for the test only this test functionality is tried.
43+
const el = currentNode.el;
44+
const eachStack = currentNode.eachStack;
45+
const currentEachStackValue = eachStackValues[0];
46+
currentEachStackValue(el, eachStack, "");
47+
}
48+
DynamicNodeComponentType.stack = [];
49+
}
50+
};
51+
DynamicNodeComponentType.clearStack = clearStack;
3252
return DynamicNodeComponentType;
3353
};

src/core/functions/data/create-element.ts

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
import { EACH_INDEX_NAME } from "../../../config/config";
33
import {
44
DynamicEachDataType,
5+
EachStackType,
56
EachTemplateType,
67
ExportDataType,
78
ExportDynamicType,
9+
GetStackType,
810
ImportDataType,
911
NodeNodesType,
1012
NodeType,
1113
RenderNodeFunctionType,
14+
SetStackType,
1215
StackType
1316
} from "../../../types/types";
1417

@@ -55,6 +58,47 @@ export const createElement = (
5558
eachValue
5659
)
5760
: null;
61+
const eachStack = {};
62+
const currentNode: NodeType = {
63+
values: newValues,
64+
ri: renderImport,
65+
dataId,
66+
nodes: newNodes,
67+
stack,
68+
el,
69+
key,
70+
eachStack
71+
};
72+
const getDefaultStack = () => {
73+
return currentNode.eachStack!;
74+
};
75+
const updateStack = (attr = getDefaultStack()) => {
76+
return attr;
77+
};
78+
const setStack: SetStackType = (attribute: any = updateStack) => {
79+
const newStack = attribute(getDefaultStack());
80+
if (currentComponent.stack.indexOf(eachIndex) === -1) {
81+
currentComponent.stack.push(eachIndex);
82+
}
83+
const { template } = currentComponent;
84+
const { eachStackValues } = template;
85+
currentNode.eachStack = newStack;
86+
// So far for the main element. The logic used for values ​​will be done later, but for the test only this test functionality is tried.
87+
const el = currentNode.el;
88+
const eachStack = currentNode.eachStack;
89+
for (let i = 0; i < eachStackValues.length; i++) {
90+
const currentEachStackValue = eachStackValues[i];
91+
currentEachStackValue(el, eachStack);
92+
}
93+
};
94+
const getStack: GetStackType = () => {
95+
const eachObj: EachStackType = {
96+
currentStack: getDefaultStack(),
97+
clearStack: currentComponent.clearStack,
98+
setStack
99+
};
100+
return eachObj;
101+
};
58102
for (let i = 0; i < length; i++) {
59103
const templateNode = templateNodes[i];
60104
const { render, rootId } = templateNode;
@@ -70,17 +114,9 @@ export const createElement = (
70114
key,
71115
exportFunctions,
72116
currentExport,
73-
eachValue
117+
eachValue,
118+
getStack
74119
);
75120
}
76-
const currentNode: NodeType = {
77-
values: newValues,
78-
ri: renderImport,
79-
dataId,
80-
nodes: newNodes,
81-
stack,
82-
el,
83-
key
84-
};
85121
return { el: el as Element, currentNode };
86122
};

src/core/functions/parse/parse-key.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,13 @@ export const parseKey = (
4949
values?: ValuesType,
5050
valueName?: string,
5151
importedDataName?: string,
52+
stackName?: string,
5253
indexName?: string,
5354
isClass?: boolean,
5455
isCondition?: boolean
5556
): CurrentKeyType => {
56-
const [renderedKey, isValue, isObj] = validateIsValue(renderKey(key), key);
57+
const currentKey = renderKey(key);
58+
const [renderedKey, isValue, isObj] = validateIsValue(currentKey, key);
5759
const originKey = (
5860
isObj ? (renderedKey as DynamicKeyObjectType).key : renderedKey
5961
) as string;
@@ -67,6 +69,7 @@ export const parseKey = (
6769
currentObj,
6870
valueName,
6971
importedDataName,
72+
stackName,
7073
indexName
7174
);
7275
} else {
@@ -89,6 +92,9 @@ export const parseKey = (
8992
if (isProperty) createError("Error properties");
9093
originType = 3;
9194
break;
95+
case stackName:
96+
originType = 4;
97+
break;
9298
}
9399
const isValSingle = val?.length === 1;
94100
const keyObj: CurrentKeyType = {

0 commit comments

Comments
 (0)