@arrai-innovations/reactive-helpers 8.0.4 → 8.1.0
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/.eslintrc.cjs +0 -4
- package/jsdoc-to-markdown.sh +4 -3
- package/package.json +8 -11
- package/tests/unit/.eslintrc.cjs +4 -4
- package/tests/unit/crudPromise.js +1 -1
- package/tests/unit/mockOnUnmounted.js +2 -2
- package/tests/unit/use/cancellableIntent.spec.js +150 -0
- package/tests/unit/use/listCalculated.spec.js +6 -8
- package/tests/unit/use/listFilter.spec.js +21 -17
- package/tests/unit/use/listInstance.spec.js +53 -59
- package/tests/unit/use/listRelated.spec.js +7 -8
- package/tests/unit/use/listSort.spec.js +29 -19
- package/tests/unit/use/listSubscription.spec.js +73 -51
- package/tests/unit/use/objectInstance.spec.js +141 -95
- package/tests/unit/use/objectSubscription.spec.js +69 -56
- package/tests/unit/use/watches.spec.js +17 -17
- package/tests/unit/utils/assignReactiveObject.spec.js +1 -1
- package/tests/unit/utils/classes.spec.js +136 -0
- package/use/combineClasses.js +22 -0
- package/use/index.js +17 -16
- package/utils/assignReactiveObject.js +1 -1
- package/utils/classes.js +107 -0
- package/utils/index.js +2 -0
- package/utils/keyDiff.js +2 -2
- package/vitest.config.js +11 -0
- package/babel.config.js +0 -15
- package/jest.config.mjs +0 -27
package/utils/classes.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import identity from "lodash-es/identity";
|
|
2
|
+
import isArray from "lodash-es/isArray";
|
|
3
|
+
import isEmpty from "lodash-es/isEmpty";
|
|
4
|
+
import isObject from "lodash-es/isObject";
|
|
5
|
+
import isSet from "lodash-es/isSet";
|
|
6
|
+
import isString from "lodash-es/isString";
|
|
7
|
+
import { isRef, unref } from "vue";
|
|
8
|
+
|
|
9
|
+
export const objectifyClasses = (...classes) => {
|
|
10
|
+
const flatClasses = classes.flat(Infinity).filter(identity);
|
|
11
|
+
const objects = flatClasses.map((c) => {
|
|
12
|
+
if (isString(c)) {
|
|
13
|
+
c = c.split(/\s+/);
|
|
14
|
+
c = c.reduce((acc, c) => {
|
|
15
|
+
acc[c] = true;
|
|
16
|
+
return acc;
|
|
17
|
+
}, {});
|
|
18
|
+
}
|
|
19
|
+
if (!isObject(c)) {
|
|
20
|
+
throw new Error(`Expected string or object, got ${c}`);
|
|
21
|
+
}
|
|
22
|
+
return c;
|
|
23
|
+
});
|
|
24
|
+
if (objects.some(isRef)) {
|
|
25
|
+
// don't just mash refs into each other or other objects.
|
|
26
|
+
// since it will change the order of operations, we can't mash objects with refs in between
|
|
27
|
+
// mash sequences of objects as delimited by refs
|
|
28
|
+
const objectGroups = [];
|
|
29
|
+
let currentGroup = [];
|
|
30
|
+
for (const object of objects) {
|
|
31
|
+
if (isRef(object)) {
|
|
32
|
+
if (currentGroup.length) {
|
|
33
|
+
objectGroups.push(currentGroup);
|
|
34
|
+
currentGroup = [];
|
|
35
|
+
}
|
|
36
|
+
objectGroups.push(object);
|
|
37
|
+
} else {
|
|
38
|
+
currentGroup.push(object);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (currentGroup.length) {
|
|
42
|
+
objectGroups.push(currentGroup);
|
|
43
|
+
}
|
|
44
|
+
return objectGroups.map((group) => {
|
|
45
|
+
if (isRef(group)) {
|
|
46
|
+
return group;
|
|
47
|
+
}
|
|
48
|
+
return Object.assign({}, ...group);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return Object.assign({}, ...objects);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const deepUnrefArrays = (val) => {
|
|
55
|
+
// object values as refs is fine, but array elements as refs should be unref'd
|
|
56
|
+
let checkedVal = isRef(val) ? unref(val) : val;
|
|
57
|
+
|
|
58
|
+
if (!isObject(checkedVal)) {
|
|
59
|
+
// primatives
|
|
60
|
+
return checkedVal;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (isSet(checkedVal)) {
|
|
64
|
+
checkedVal = Array.from(checkedVal);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (isArray(checkedVal)) {
|
|
68
|
+
return checkedVal.map(deepUnrefArrays);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return checkedVal;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export const combineClasses = (...classes) => {
|
|
75
|
+
// we unref your refs, so probably want a computed around this
|
|
76
|
+
// ultimately, strings and objects are classes, arrays are organization and containers
|
|
77
|
+
const rawClasses = deepUnrefArrays(classes);
|
|
78
|
+
const flattenedClasses = rawClasses.flat(Infinity);
|
|
79
|
+
const filteredClasses = flattenedClasses.filter(identity);
|
|
80
|
+
const hasStrings = filteredClasses.some(isString);
|
|
81
|
+
const hasObjects = filteredClasses.some(isObject);
|
|
82
|
+
if (hasStrings && !hasObjects) {
|
|
83
|
+
return filteredClasses.join(" ");
|
|
84
|
+
} else if (hasObjects && !hasStrings) {
|
|
85
|
+
return Object.assign({}, ...filteredClasses);
|
|
86
|
+
}
|
|
87
|
+
const result = objectifyClasses(...filteredClasses);
|
|
88
|
+
return isEmpty(result) ? undefined : result;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export const stringifyClass = (cls) => {
|
|
92
|
+
if (isArray(cls)) {
|
|
93
|
+
return stringifyClasses(...cls);
|
|
94
|
+
} else if (isObject(cls)) {
|
|
95
|
+
return Object.keys(cls)
|
|
96
|
+
.filter((key) => cls[key])
|
|
97
|
+
.join(" ");
|
|
98
|
+
} else {
|
|
99
|
+
return cls;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export const stringifyClasses = (...classes) =>
|
|
104
|
+
classes
|
|
105
|
+
.map(stringifyClass)
|
|
106
|
+
.filter((x) => x)
|
|
107
|
+
.join(" ");
|
package/utils/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from "./assignReactiveObject";
|
|
2
|
+
export * from "./classes";
|
|
2
3
|
export * from "./debugMessage";
|
|
3
4
|
export * from "./debugWatch";
|
|
4
5
|
export * from "./flattenPaths";
|
|
@@ -7,4 +8,5 @@ export * from "./keyDiff";
|
|
|
7
8
|
export * from "./lifecycleDebug";
|
|
8
9
|
export * from "./loadingCombine";
|
|
9
10
|
export * from "./set";
|
|
11
|
+
export * from "./transformWalk";
|
|
10
12
|
export * from "./watches";
|
package/utils/keyDiff.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { flattenPaths } from "./flattenPaths
|
|
2
|
-
import { difference, intersection } from "./set
|
|
1
|
+
import { flattenPaths } from "./flattenPaths";
|
|
2
|
+
import { difference, intersection } from "./set";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Calculate the difference between objects in terms of what keys
|
package/vitest.config.js
ADDED
package/babel.config.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
// Only used by Jest
|
|
2
|
-
module.exports = {
|
|
3
|
-
presets: [["@babel/preset-env", { useBuiltIns: "entry", corejs: "2", targets: { node: "current" } }]],
|
|
4
|
-
plugins: [
|
|
5
|
-
function () {
|
|
6
|
-
return {
|
|
7
|
-
visitor: {
|
|
8
|
-
MetaProperty(path) {
|
|
9
|
-
path.replaceWithSourceString("process");
|
|
10
|
-
},
|
|
11
|
-
},
|
|
12
|
-
};
|
|
13
|
-
},
|
|
14
|
-
],
|
|
15
|
-
};
|
package/jest.config.mjs
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import path, { dirname } from "path";
|
|
2
|
-
import { fileURLToPath } from "url";
|
|
3
|
-
|
|
4
|
-
export default {
|
|
5
|
-
rootDir: path.resolve(dirname(fileURLToPath(import.meta.url))),
|
|
6
|
-
clearMocks: true,
|
|
7
|
-
coverageDirectory: "coverage",
|
|
8
|
-
coverageProvider: "babel",
|
|
9
|
-
coverageReporters: ["json-summary", "html", "clover", "text"],
|
|
10
|
-
moduleFileExtensions: ["vue", "js", "json"],
|
|
11
|
-
moduleNameMapper: {
|
|
12
|
-
"@/(.*)$": "<rootDir>/src/$1",
|
|
13
|
-
"~/(.*)$": "<rootDir>/node_modules/$1",
|
|
14
|
-
},
|
|
15
|
-
testEnvironment: "jsdom",
|
|
16
|
-
testMatch: ["<rootDir>/tests/unit/**/*.spec.js"],
|
|
17
|
-
testPathIgnorePatterns: [],
|
|
18
|
-
transform: {
|
|
19
|
-
"^.+\\.vue$": "@vue/vue3-jest",
|
|
20
|
-
"^.+\\js$": "babel-jest",
|
|
21
|
-
},
|
|
22
|
-
globals: {
|
|
23
|
-
"@vue/vue3-jest": {
|
|
24
|
-
babelConfig: true,
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
};
|