@knotx/utils 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +18 -0
- package/dist/index.d.cts +2 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +18 -1
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -25,6 +25,23 @@ function flattenOperations(operations) {
|
|
|
25
25
|
return operation;
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
|
+
function buildResetOperation(previousDataMap, dataMap) {
|
|
29
|
+
const operations = [];
|
|
30
|
+
previousDataMap.forEach((_, id) => {
|
|
31
|
+
if (!dataMap.has(id)) {
|
|
32
|
+
operations.push({ type: "remove", id });
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
dataMap.forEach((data, id) => {
|
|
36
|
+
if (!previousDataMap.has(id)) {
|
|
37
|
+
operations.push({ type: "add", data });
|
|
38
|
+
}
|
|
39
|
+
if (previousDataMap.has(id) && !Object.is(previousDataMap.get(id), data)) {
|
|
40
|
+
operations.push({ type: "update", id, data });
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
return { type: "batch", operations, isInit: false };
|
|
44
|
+
}
|
|
28
45
|
|
|
29
46
|
function getSymbol(name) {
|
|
30
47
|
return Symbol.for(`knotx:${name}`);
|
|
@@ -32,6 +49,7 @@ function getSymbol(name) {
|
|
|
32
49
|
|
|
33
50
|
exports.addBemModifier = addBemModifier;
|
|
34
51
|
exports.bem = bem;
|
|
52
|
+
exports.buildResetOperation = buildResetOperation;
|
|
35
53
|
exports.flattenOperations = flattenOperations;
|
|
36
54
|
exports.generateId = generateId;
|
|
37
55
|
exports.getSymbol = getSymbol;
|
package/dist/index.d.cts
CHANGED
|
@@ -14,9 +14,10 @@ declare function isDraftOperation<T extends IData>(operation: DataOperation<T>):
|
|
|
14
14
|
draftId: string;
|
|
15
15
|
}>;
|
|
16
16
|
declare function flattenOperations<T extends IData>(operations: DataOperation<T>[]): DataOperation<T>[];
|
|
17
|
+
declare function buildResetOperation<T extends IData>(previousDataMap: Map<string, T>, dataMap: Map<string, T>): DataBatchOperation<T>;
|
|
17
18
|
|
|
18
19
|
declare function getSymbol<TName extends string>(name: TName): symbol & {
|
|
19
20
|
__knotx__?: TName;
|
|
20
21
|
};
|
|
21
22
|
|
|
22
|
-
export { addBemModifier, bem, flattenOperations, generateId, getSymbol, isDraftOperation, isInitOperation };
|
|
23
|
+
export { addBemModifier, bem, buildResetOperation, flattenOperations, generateId, getSymbol, isDraftOperation, isInitOperation };
|
package/dist/index.d.mts
CHANGED
|
@@ -14,9 +14,10 @@ declare function isDraftOperation<T extends IData>(operation: DataOperation<T>):
|
|
|
14
14
|
draftId: string;
|
|
15
15
|
}>;
|
|
16
16
|
declare function flattenOperations<T extends IData>(operations: DataOperation<T>[]): DataOperation<T>[];
|
|
17
|
+
declare function buildResetOperation<T extends IData>(previousDataMap: Map<string, T>, dataMap: Map<string, T>): DataBatchOperation<T>;
|
|
17
18
|
|
|
18
19
|
declare function getSymbol<TName extends string>(name: TName): symbol & {
|
|
19
20
|
__knotx__?: TName;
|
|
20
21
|
};
|
|
21
22
|
|
|
22
|
-
export { addBemModifier, bem, flattenOperations, generateId, getSymbol, isDraftOperation, isInitOperation };
|
|
23
|
+
export { addBemModifier, bem, buildResetOperation, flattenOperations, generateId, getSymbol, isDraftOperation, isInitOperation };
|
package/dist/index.d.ts
CHANGED
|
@@ -14,9 +14,10 @@ declare function isDraftOperation<T extends IData>(operation: DataOperation<T>):
|
|
|
14
14
|
draftId: string;
|
|
15
15
|
}>;
|
|
16
16
|
declare function flattenOperations<T extends IData>(operations: DataOperation<T>[]): DataOperation<T>[];
|
|
17
|
+
declare function buildResetOperation<T extends IData>(previousDataMap: Map<string, T>, dataMap: Map<string, T>): DataBatchOperation<T>;
|
|
17
18
|
|
|
18
19
|
declare function getSymbol<TName extends string>(name: TName): symbol & {
|
|
19
20
|
__knotx__?: TName;
|
|
20
21
|
};
|
|
21
22
|
|
|
22
|
-
export { addBemModifier, bem, flattenOperations, generateId, getSymbol, isDraftOperation, isInitOperation };
|
|
23
|
+
export { addBemModifier, bem, buildResetOperation, flattenOperations, generateId, getSymbol, isDraftOperation, isInitOperation };
|
package/dist/index.js
CHANGED
|
@@ -23,9 +23,26 @@ function flattenOperations(operations) {
|
|
|
23
23
|
return operation;
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
|
+
function buildResetOperation(previousDataMap, dataMap) {
|
|
27
|
+
const operations = [];
|
|
28
|
+
previousDataMap.forEach((_, id) => {
|
|
29
|
+
if (!dataMap.has(id)) {
|
|
30
|
+
operations.push({ type: "remove", id });
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
dataMap.forEach((data, id) => {
|
|
34
|
+
if (!previousDataMap.has(id)) {
|
|
35
|
+
operations.push({ type: "add", data });
|
|
36
|
+
}
|
|
37
|
+
if (previousDataMap.has(id) && !Object.is(previousDataMap.get(id), data)) {
|
|
38
|
+
operations.push({ type: "update", id, data });
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
return { type: "batch", operations, isInit: false };
|
|
42
|
+
}
|
|
26
43
|
|
|
27
44
|
function getSymbol(name) {
|
|
28
45
|
return Symbol.for(`knotx:${name}`);
|
|
29
46
|
}
|
|
30
47
|
|
|
31
|
-
export { addBemModifier, bem, flattenOperations, generateId, getSymbol, isDraftOperation, isInitOperation };
|
|
48
|
+
export { addBemModifier, bem, buildResetOperation, flattenOperations, generateId, getSymbol, isDraftOperation, isInitOperation };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knotx/utils",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Utils for Knotx",
|
|
5
5
|
"author": "boenfu",
|
|
6
6
|
"license": "MIT",
|
|
@@ -28,15 +28,15 @@
|
|
|
28
28
|
"dist"
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@knotx/data": "0.2.
|
|
31
|
+
"@knotx/data": "0.2.3"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@knotx/
|
|
35
|
-
"@knotx/eslint-config": "0.2.
|
|
36
|
-
"@knotx/
|
|
34
|
+
"@knotx/typescript-config": "0.2.3",
|
|
35
|
+
"@knotx/eslint-config": "0.2.3",
|
|
36
|
+
"@knotx/build-config": "0.2.3"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
|
-
"build": "unbuild
|
|
39
|
+
"build": "unbuild",
|
|
40
40
|
"dev": "unbuild --stub",
|
|
41
41
|
"lint": "eslint .",
|
|
42
42
|
"typecheck": "tsc --noEmit"
|