@arrai-innovations/reactive-helpers 11.4.2 → 13.0.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/.husky/pre-commit +0 -1
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.prettierignore +1 -0
- package/README.md +11 -10
- package/config/listCrud.js +32 -1
- package/config/objectCrud.js +47 -1
- package/docs/README.md +43 -0
- package/docs/config/listCrud.md +97 -0
- package/docs/config/objectCrud.md +123 -0
- package/docs/use/cancellableIntent.md +163 -0
- package/docs/use/combineClasses.md +52 -0
- package/docs/use/list.md +285 -0
- package/docs/use/listCalculated.md +773 -0
- package/docs/use/listFilter.md +877 -0
- package/docs/use/listInstance.md +483 -0
- package/docs/use/listKeys.md +91 -0
- package/docs/use/listRelated.md +685 -0
- package/docs/use/listSearch.md +889 -0
- package/docs/use/listSort.md +1144 -0
- package/docs/use/listSubscription.md +379 -0
- package/docs/use/loadingError.md +21 -0
- package/docs/use/object.md +437 -0
- package/docs/use/objectCalculated.md +606 -0
- package/docs/use/objectInstance.md +486 -0
- package/docs/use/objectRelated.md +588 -0
- package/docs/use/objectSubscription.md +459 -0
- package/docs/use/paginatedListInstance.md +147 -0
- package/docs/use/search.md +311 -0
- package/docs/use/watchesRunning.md +80 -0
- package/docs/utils/assignReactiveObject.md +351 -0
- package/docs/utils/classes.md +100 -0
- package/docs/utils/compact.md +57 -0
- package/docs/utils/deleteKey.md +53 -0
- package/docs/utils/flattenPaths.md +45 -0
- package/docs/utils/getFakeId.md +34 -0
- package/docs/utils/keyDiff.md +101 -0
- package/docs/utils/loadingCombine.md +28 -0
- package/docs/utils/proxyRunning.md +33 -0
- package/docs/utils/relatedCalculatedHelpers.md +75 -0
- package/docs/utils/set.md +139 -0
- package/docs/utils/transformWalk.md +33 -0
- package/docs/utils/watches.md +441 -0
- package/eslint.config.js +125 -0
- package/index.js +34 -3
- package/lint-staged.config.js +5 -1
- package/makeTypeDoc.sh +25 -0
- package/package.json +27 -19
- package/tests/unit/config/listCrud.spec.js +5 -0
- package/tests/unit/config/objectCrud.spec.js +5 -0
- package/tests/unit/crudPromise.js +22 -3
- package/tests/unit/mockOnUnmounted.js +1 -1
- package/tests/unit/use/cancellableIntent.spec.js +2 -0
- package/tests/unit/use/listCalculated.spec.js +4 -3
- package/tests/unit/use/listFilter.spec.js +11 -7
- package/tests/unit/use/listInstance.spec.js +32 -14
- package/tests/unit/use/listRelated.spec.js +3 -2
- package/tests/unit/use/listSearch.spec.js +9 -7
- package/tests/unit/use/listSort.spec.js +29 -22
- package/tests/unit/use/listSubscription.spec.js +11 -5
- package/tests/unit/use/objectInstance.spec.js +15 -2
- package/tests/unit/use/objectSubscription.spec.js +31 -16
- package/tests/unit/use/search.spec.js +2 -2
- package/tests/unit/utils/assignReactiveObject.spec.js +21 -13
- package/tests/unit/utils/classes.spec.js +7 -6
- package/tests/unit/utils/watches.spec.js +4 -4
- package/tsconfig.json +19 -0
- package/typedoc-local-plugins/customize-output.js +13 -0
- package/typedoc.json +12 -0
- package/use/cancellableIntent.js +73 -2
- package/use/combineClasses.js +41 -31
- package/use/list.js +139 -5
- package/use/listCalculated.js +175 -10
- package/use/listFilter.js +175 -21
- package/use/listInstance.js +215 -94
- package/use/listRelated.js +260 -72
- package/use/listSearch.js +178 -57
- package/use/listSort.js +188 -21
- package/use/listSubscription.js +211 -63
- package/use/loadingError.js +43 -0
- package/use/object.js +187 -23
- package/use/objectCalculated.js +168 -16
- package/use/objectInstance.js +183 -102
- package/use/objectRelated.js +276 -84
- package/use/objectSubscription.js +169 -17
- package/use/paginatedListInstance.js +30 -1
- package/use/search.js +39 -23
- package/use/watchesRunning.js +41 -6
- package/utils/assignReactiveObject.js +139 -88
- package/utils/classes.js +57 -48
- package/utils/compact.js +28 -2
- package/utils/deleteKey.js +14 -1
- package/utils/flattenPaths.js +19 -9
- package/utils/getFakeId.js +11 -1
- package/utils/keyDiff.js +26 -35
- package/utils/loadingCombine.js +7 -4
- package/utils/proxyRunning.js +16 -8
- package/utils/relatedCalculatedHelpers.js +17 -0
- package/utils/set.js +66 -0
- package/utils/transformWalk.js +7 -6
- package/utils/watches.js +205 -71
- package/.eslintignore +0 -2
- package/.eslintrc.cjs +0 -25
- package/.jsdoc2md.json +0 -4
- package/config/index.js +0 -2
- package/docs.md +0 -1002
- package/jsdoc-to-markdown.sh +0 -16
- package/tests/unit/.eslintrc.cjs +0 -11
- package/tests/unit/config/index.spec.js +0 -18
- package/tests/unit/use/index.spec.js +0 -18
- package/tests/unit/utils/index.spec.js +0 -18
- package/use/index.js +0 -19
- package/utils/debugMessage.js +0 -209
- package/utils/debugWatch.js +0 -29
- package/utils/index.js +0 -16
- package/utils/lifecycleDebug.js +0 -126
package/jsdoc-to-markdown.sh
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
set -e
|
|
3
|
-
npx --no-install jsdoc-to-markdown > ./docs.new.md
|
|
4
|
-
npx --no-install prettier --write docs.new.md > /dev/null
|
|
5
|
-
set +e
|
|
6
|
-
diff ./docs.new.md ./docs.md > /dev/null
|
|
7
|
-
diffCode=$?
|
|
8
|
-
# we want to return a non-zero exit code if the files are different, to stop the commit
|
|
9
|
-
if [ $diffCode != 0 ]; then
|
|
10
|
-
echo "docs.md is out of date, see git diff for details"
|
|
11
|
-
mv -f ./docs.new.md ./docs.md
|
|
12
|
-
exit $diffCode
|
|
13
|
-
fi
|
|
14
|
-
rm -f ./docs.new.md
|
|
15
|
-
git rm ./docs.new.md > /dev/null 2>&1
|
|
16
|
-
exit 0
|
package/tests/unit/.eslintrc.cjs
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
plugins: ["vitest"],
|
|
3
|
-
extends: ["eslint:recommended", "plugin:vitest/recommended", "plugin:vitest-globals/recommended"],
|
|
4
|
-
env: {
|
|
5
|
-
"vitest-globals/env": true,
|
|
6
|
-
},
|
|
7
|
-
rules: {
|
|
8
|
-
"vitest/no-conditional-expect": "off",
|
|
9
|
-
"vitest/valid-expect": "off", // we want to use expect(value, message).toBe(expected), which is not supported by this rule
|
|
10
|
-
},
|
|
11
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import * as config from "../../../config/index.js";
|
|
2
|
-
import fs from "fs/promises";
|
|
3
|
-
|
|
4
|
-
describe("config/index.js", function () {
|
|
5
|
-
it("should export everything exported by individual files", async function () {
|
|
6
|
-
const files = await fs.readdir("./config");
|
|
7
|
-
const modules = files.filter((file) => file.endsWith(".js") && file !== "index.js");
|
|
8
|
-
const exportedKeys = [];
|
|
9
|
-
for (const module of modules) {
|
|
10
|
-
const moduleExports = await import(`../../../config/${module}`);
|
|
11
|
-
exportedKeys.push(...Object.keys(moduleExports).filter((key) => key !== "default"));
|
|
12
|
-
}
|
|
13
|
-
const useKeys = Object.keys(config);
|
|
14
|
-
useKeys.sort();
|
|
15
|
-
exportedKeys.sort();
|
|
16
|
-
expect(useKeys).toEqual(exportedKeys);
|
|
17
|
-
});
|
|
18
|
-
});
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import * as use from "../../../use/index.js";
|
|
2
|
-
import fs from "fs/promises";
|
|
3
|
-
|
|
4
|
-
describe("use/index.js", function () {
|
|
5
|
-
it("should export everything exported by individual files", async function () {
|
|
6
|
-
const files = await fs.readdir("./use");
|
|
7
|
-
const modules = files.filter((file) => file.endsWith(".js") && file !== "index.js");
|
|
8
|
-
const exportedKeys = [];
|
|
9
|
-
for (const module of modules) {
|
|
10
|
-
const moduleExports = await import(`../../../use/${module}`);
|
|
11
|
-
exportedKeys.push(...Object.keys(moduleExports).filter((key) => key !== "default"));
|
|
12
|
-
}
|
|
13
|
-
const useKeys = Object.keys(use);
|
|
14
|
-
useKeys.sort();
|
|
15
|
-
exportedKeys.sort();
|
|
16
|
-
expect(useKeys).toEqual(exportedKeys);
|
|
17
|
-
});
|
|
18
|
-
});
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import * as utils from "../../../utils/index.js";
|
|
2
|
-
import fs from "fs/promises";
|
|
3
|
-
|
|
4
|
-
describe("utils/index.js", function () {
|
|
5
|
-
it("should export everything exported by individual files", async function () {
|
|
6
|
-
const files = await fs.readdir("./utils");
|
|
7
|
-
const modules = files.filter((file) => file.endsWith(".js") && file !== "index.js");
|
|
8
|
-
const exportedKeys = [];
|
|
9
|
-
for (const module of modules) {
|
|
10
|
-
const moduleExports = await import(`../../../utils/${module}`);
|
|
11
|
-
exportedKeys.push(...Object.keys(moduleExports).filter((key) => key !== "default"));
|
|
12
|
-
}
|
|
13
|
-
const utilsKeys = Object.keys(utils);
|
|
14
|
-
utilsKeys.sort();
|
|
15
|
-
exportedKeys.sort();
|
|
16
|
-
expect(utilsKeys).toEqual(exportedKeys);
|
|
17
|
-
});
|
|
18
|
-
});
|
package/use/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export * from "./cancellableIntent.js";
|
|
2
|
-
export * from "./combineClasses.js";
|
|
3
|
-
export * from "./list.js";
|
|
4
|
-
export * from "./listCalculated.js";
|
|
5
|
-
export * from "./listKeys.js";
|
|
6
|
-
export * from "./listFilter.js";
|
|
7
|
-
export * from "./listInstance.js";
|
|
8
|
-
export * from "./listRelated.js";
|
|
9
|
-
export * from "./listSearch.js";
|
|
10
|
-
export * from "./listSort.js";
|
|
11
|
-
export * from "./listSubscription.js";
|
|
12
|
-
export * from "./object.js";
|
|
13
|
-
export * from "./objectCalculated.js";
|
|
14
|
-
export * from "./objectInstance.js";
|
|
15
|
-
export * from "./objectRelated.js";
|
|
16
|
-
export * from "./objectSubscription.js";
|
|
17
|
-
export * from "./paginatedListInstance.js";
|
|
18
|
-
export * from "./search.js";
|
|
19
|
-
export * from "./watchesRunning.js";
|
package/utils/debugMessage.js
DELETED
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
import { isSuperset } from "./set.js";
|
|
2
|
-
import { transformWalk } from "./transformWalk.js";
|
|
3
|
-
import debounce from "lodash-es/debounce.js";
|
|
4
|
-
import isSet from "lodash-es/isSet.js";
|
|
5
|
-
import partial from "lodash-es/partial.js";
|
|
6
|
-
import union from "lodash-es/union.js";
|
|
7
|
-
import { unref } from "vue";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Configurable logging of debug messages at runtime.
|
|
11
|
-
* @module utils/debugMessage
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Whether debug messages are enabled or not. For deploying to production with debugging but not
|
|
16
|
-
* spamming everyone with debug messages.
|
|
17
|
-
* @type {boolean}
|
|
18
|
-
*/
|
|
19
|
-
window.RH_DEBUG = false;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Map of categories to whether they are enabled or not. The order of the entries are important.
|
|
23
|
-
* All categories in the key must be present for the entry to match.
|
|
24
|
-
* The first matching entry with a value opf true will show the message.
|
|
25
|
-
* The first matching entry with a value of false will hide the message.
|
|
26
|
-
* The special category "*" will match all messages.
|
|
27
|
-
* Strings passed as keys will be treated as a single category.
|
|
28
|
-
* Sets can also be passed as keys, which is what the arrays get converted to.
|
|
29
|
-
* @type {Map<string[]|string|Set, boolean>}
|
|
30
|
-
* @example
|
|
31
|
-
* window.RH_DEBUG = true; // turn it on
|
|
32
|
-
* window.RH_DEBUG_CATEGORIES.set(["ofc-form-component", "lifecycle"], true); // show messages matching both categories
|
|
33
|
-
* window.RH_DEBUG_CATEGORIES.set(["lifecycle"], false); // turn off lifecycle messages not matching the above
|
|
34
|
-
* window.RH_DEBUG_CATEGORIES.set(["dropDown"], true); // show dropDown messages except where disabled by the above
|
|
35
|
-
* window.RH_DEBUG_CATEGORIES.set(["*"], false); // turn off all messages not matching the above
|
|
36
|
-
*/
|
|
37
|
-
window.RH_DEBUG_CATEGORIES = new Map();
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Group identical messages together and show a count of how many times they were logged.
|
|
41
|
-
* Messages are only shown on the trailing edge, so logging is delayed and somewhat out of order.
|
|
42
|
-
* @type {boolean}
|
|
43
|
-
*/
|
|
44
|
-
window.RH_DEBOUNCE_DEBUG = false;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Whether to process arguments to be more friendly for console.log, with regard to circular references
|
|
48
|
-
* and not recursing into vue components.
|
|
49
|
-
* @type {boolean}
|
|
50
|
-
*/
|
|
51
|
-
window.RH_TRANSFORM_MESSAGES = true;
|
|
52
|
-
|
|
53
|
-
const DEBOUNCE_WAIT = 50;
|
|
54
|
-
const log = console.log;
|
|
55
|
-
const messageBounceFns = {};
|
|
56
|
-
const counts = {};
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* @private
|
|
60
|
-
* @param {Set} categoriesSet categories for the message log
|
|
61
|
-
* @param {string} categoriesKey key for debouncing
|
|
62
|
-
* @param {Array.<*>} messages messages to log
|
|
63
|
-
*/
|
|
64
|
-
const doLog = (categoriesSet, categoriesKey, messages) => {
|
|
65
|
-
if (messages.length > 0) {
|
|
66
|
-
const key = getKey(categoriesKey, messages);
|
|
67
|
-
const count = counts[key];
|
|
68
|
-
const logArgs = [Array.from(categoriesSet).join(","), ...messages];
|
|
69
|
-
if (count > 1) {
|
|
70
|
-
logArgs.push(`(${count})`);
|
|
71
|
-
}
|
|
72
|
-
log(...logArgs);
|
|
73
|
-
delete counts[key];
|
|
74
|
-
delete messageBounceFns[key];
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Process a value for logging, dealing with circular references and
|
|
80
|
-
* not recursing into vue components.
|
|
81
|
-
* @private
|
|
82
|
-
* @function inspectWalkFn
|
|
83
|
-
* @param {Map} seenObjects for circlular reference detection
|
|
84
|
-
* @param {string} key keys is an unused argument from walk
|
|
85
|
-
* @param {*} value value to process
|
|
86
|
-
* @param {string} path path to the value, used for display in circular references
|
|
87
|
-
* @returns {*} processed value
|
|
88
|
-
*/
|
|
89
|
-
export const inspectWalkFn = (seenObjects, key, value, path) => {
|
|
90
|
-
// return primatives as-is
|
|
91
|
-
if (typeof value !== "object" || value === null) {
|
|
92
|
-
return value;
|
|
93
|
-
}
|
|
94
|
-
if (seenObjects.has(value)) {
|
|
95
|
-
return `「Dupe:${seenObjects.get(value)}」`;
|
|
96
|
-
}
|
|
97
|
-
seenObjects.set(value, path);
|
|
98
|
-
if (value?.type?.__name) {
|
|
99
|
-
// vue component instance
|
|
100
|
-
return `⧼ Component:${value.type.__name} ⧽`;
|
|
101
|
-
}
|
|
102
|
-
return value;
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* @private
|
|
107
|
-
* @param {Array.<string | Function>} messages messages to resolve
|
|
108
|
-
* @returns {Array.<*>} resolved messages
|
|
109
|
-
*/
|
|
110
|
-
const resolveMessages = (messages) => {
|
|
111
|
-
const resolvedMessages = [];
|
|
112
|
-
for (const message of messages) {
|
|
113
|
-
let toPush = unref(typeof message === "function" ? message() : message);
|
|
114
|
-
if (window.RH_TRANSFORM_MESSAGES) {
|
|
115
|
-
const seenObjects = new Map();
|
|
116
|
-
toPush = transformWalk(toPush, partial(inspectWalkFn, seenObjects));
|
|
117
|
-
}
|
|
118
|
-
resolvedMessages.push(toPush);
|
|
119
|
-
}
|
|
120
|
-
return resolvedMessages;
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* @private
|
|
125
|
-
* @param {Set} categoriesSet categories for the message log
|
|
126
|
-
* @param {string} categoriesKey key for debouncing
|
|
127
|
-
* @param {Array.<*>} messages messages to log
|
|
128
|
-
* @returns {void}
|
|
129
|
-
*/
|
|
130
|
-
const doDebouncedLog = (categoriesSet, categoriesKey, messages) => {
|
|
131
|
-
if (!window.RH_DEBOUNCE_DEBUG) {
|
|
132
|
-
return doLog(categoriesSet, categoriesKey, messages);
|
|
133
|
-
}
|
|
134
|
-
const key = getKey(categoriesKey, messages);
|
|
135
|
-
let debouncedLog = messageBounceFns[key];
|
|
136
|
-
if (!debouncedLog) {
|
|
137
|
-
debouncedLog = debounce(doLog, DEBOUNCE_WAIT, { leading: false, trailing: true });
|
|
138
|
-
messageBounceFns[key] = debouncedLog;
|
|
139
|
-
}
|
|
140
|
-
debouncedLog(categoriesSet, categoriesKey, messages);
|
|
141
|
-
counts[key] = (counts[key] || 0) + 1;
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* @private
|
|
146
|
-
* @param {string} categoriesKey categories for the message log
|
|
147
|
-
* @param {Array.<string | Function>} messages messages to log
|
|
148
|
-
* @returns {string} key
|
|
149
|
-
*/
|
|
150
|
-
const getKey = (categoriesKey, messages) => `${categoriesKey}|${messages.join("-")}`;
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Logs debug messages based on the specified categories and logging rules.
|
|
154
|
-
* @typedef {object} DebugMessageFunction
|
|
155
|
-
* @property {function(...(Array.<string | Function> | string | Function)): void} messages log a message
|
|
156
|
-
*/
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Returns a function that logs debug messages based on enabled categories.
|
|
160
|
-
* @function useDebugMessage
|
|
161
|
-
* @param {string[]} categories categories for the message log
|
|
162
|
-
* @returns {DebugMessageFunction} debug message function
|
|
163
|
-
*/
|
|
164
|
-
export function useDebugMessage(categories) {
|
|
165
|
-
const categoriesSet = isSet(categories) ? categories : new Set(categories);
|
|
166
|
-
const sortedCategories = Array.from(categoriesSet).sort();
|
|
167
|
-
const categoriesKey = categoriesSet.size > 0 ? `[${sortedCategories.join(", ")}]` : "";
|
|
168
|
-
|
|
169
|
-
const debugMessage = (...messages) => {
|
|
170
|
-
if (!window.RH_DEBUG) {
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
for (const [rule, enabledOrDisabled] of window.RH_DEBUG_CATEGORIES.entries()) {
|
|
174
|
-
let ruleSet;
|
|
175
|
-
if (Array.isArray(rule)) {
|
|
176
|
-
ruleSet = new Set(rule);
|
|
177
|
-
} else if (typeof rule === "string") {
|
|
178
|
-
ruleSet = new Set(rule.split(","));
|
|
179
|
-
} else if (rule.toString() === "[object Set]") {
|
|
180
|
-
ruleSet = rule;
|
|
181
|
-
} else if (rule === "*") {
|
|
182
|
-
ruleSet = new Set(["*"]);
|
|
183
|
-
} else {
|
|
184
|
-
throw new Error(`Unexpected rule type: ${typeof rule}, ${rule}`);
|
|
185
|
-
}
|
|
186
|
-
// if categoriesSet is a superset of ruleSet, then apply the rule
|
|
187
|
-
// first applicable rule wins
|
|
188
|
-
if (isSuperset(categoriesSet, ruleSet) || ruleSet.has("*")) {
|
|
189
|
-
if (enabledOrDisabled === true) {
|
|
190
|
-
doDebouncedLog(categoriesSet, categoriesKey, resolveMessages(messages));
|
|
191
|
-
return;
|
|
192
|
-
} else if (enabledOrDisabled === false) {
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
// ignore other values
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
doDebouncedLog(categoriesSet, categoriesKey, resolveMessages(messages));
|
|
199
|
-
};
|
|
200
|
-
/**
|
|
201
|
-
* @param {string[]} moreCategories categories to add
|
|
202
|
-
* @returns {DebugMessageFunction} new debug message function
|
|
203
|
-
*/
|
|
204
|
-
debugMessage.more = (moreCategories) => {
|
|
205
|
-
// return a new debugMessage so the added categories are only applied to the new debugMessage
|
|
206
|
-
return useDebugMessage(union(categoriesSet, isSet(moreCategories) ? moreCategories : new Set(moreCategories)));
|
|
207
|
-
};
|
|
208
|
-
return debugMessage;
|
|
209
|
-
}
|
package/utils/debugWatch.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { keyDiff } from "./keyDiff.js";
|
|
2
|
-
import isEqual from "lodash-es/isEqual.js";
|
|
3
|
-
import { watch } from "vue";
|
|
4
|
-
import { deepUnref } from "vue-deepunref";
|
|
5
|
-
|
|
6
|
-
export const debugWatch = (target, name) => {
|
|
7
|
-
return watch(
|
|
8
|
-
() => deepUnref(target),
|
|
9
|
-
(newState, oldState) => {
|
|
10
|
-
console.log(`Watch triggered ${name}`);
|
|
11
|
-
const diff = keyDiff(Object.keys(newState || {}), Object.keys(oldState || {}));
|
|
12
|
-
for (const addedKey of Array.from(diff.addedKeys)) {
|
|
13
|
-
console.log(`${name} added key ${addedKey}`, deepUnref(newState[addedKey]));
|
|
14
|
-
}
|
|
15
|
-
for (const removedKey of Array.from(diff.removedKeys)) {
|
|
16
|
-
console.log(`${name} removed key ${removedKey}`, deepUnref(oldState[removedKey]));
|
|
17
|
-
}
|
|
18
|
-
for (const sameKey of Array.from(diff.sameKeys)) {
|
|
19
|
-
if (!isEqual(deepUnref(newState[sameKey]), deepUnref(oldState[sameKey]))) {
|
|
20
|
-
console.log(`${name} same key ${sameKey}`, newState[sameKey], oldState[sameKey]);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
deep: true,
|
|
26
|
-
immediate: true,
|
|
27
|
-
}
|
|
28
|
-
);
|
|
29
|
-
};
|
package/utils/index.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export * from "./assignReactiveObject.js";
|
|
2
|
-
export * from "./classes.js";
|
|
3
|
-
export * from "./compact.js";
|
|
4
|
-
export * from "./debugMessage.js";
|
|
5
|
-
export * from "./debugWatch.js";
|
|
6
|
-
export * from "./deleteKey.js";
|
|
7
|
-
export * from "./flattenPaths.js";
|
|
8
|
-
export * from "./getFakeId.js";
|
|
9
|
-
export * from "./keyDiff.js";
|
|
10
|
-
export * from "./lifecycleDebug.js";
|
|
11
|
-
export * from "./loadingCombine.js";
|
|
12
|
-
export * from "./proxyRunning.js";
|
|
13
|
-
export * from "./relatedCalculatedHelpers.js";
|
|
14
|
-
export * from "./set.js";
|
|
15
|
-
export * from "./transformWalk.js";
|
|
16
|
-
export * from "./watches.js";
|
package/utils/lifecycleDebug.js
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { inspectWalkFn, useDebugMessage } from "./debugMessage.js";
|
|
2
|
-
import { keyDiffDeep } from "./keyDiff.js";
|
|
3
|
-
import { transformWalk } from "./transformWalk.js";
|
|
4
|
-
import isEqual from "lodash-es/isEqual.js";
|
|
5
|
-
import partial from "lodash-es/partial.js";
|
|
6
|
-
import {
|
|
7
|
-
onActivated,
|
|
8
|
-
onBeforeMount,
|
|
9
|
-
onBeforeUnmount,
|
|
10
|
-
onBeforeUpdate,
|
|
11
|
-
onDeactivated,
|
|
12
|
-
onErrorCaptured,
|
|
13
|
-
onMounted,
|
|
14
|
-
onRenderTracked,
|
|
15
|
-
onRenderTriggered,
|
|
16
|
-
onServerPrefetch,
|
|
17
|
-
onUnmounted,
|
|
18
|
-
onUpdated,
|
|
19
|
-
unref,
|
|
20
|
-
} from "vue";
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Debug lifecycle hooks
|
|
24
|
-
* @module utils/lifecycleDebug
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
window.RH_DEBUG_SKIP_EMPTY_CHANGE_EFFECTS = true;
|
|
28
|
-
|
|
29
|
-
export const customHandlers = {
|
|
30
|
-
onRenderTriggered: (debugMessage, e) => {
|
|
31
|
-
const newSeenObjects = new Map();
|
|
32
|
-
const newValue = transformWalk(e.newValue, partial(inspectWalkFn, newSeenObjects));
|
|
33
|
-
const oldSeenObjects = new Map();
|
|
34
|
-
const oldValue = transformWalk(e.oldValue, partial(inspectWalkFn, oldSeenObjects));
|
|
35
|
-
let keyDiffResults;
|
|
36
|
-
if (typeof newValue !== "object" || typeof oldValue !== "object") {
|
|
37
|
-
keyDiffResults = keyDiffDeep(newValue, oldValue);
|
|
38
|
-
keyDiffResults.changedKeys = new Set();
|
|
39
|
-
for (const key of keyDiffResults.sameKeys) {
|
|
40
|
-
// since it is a deep diff, object equality is fine to not trigger a change
|
|
41
|
-
if (newValue[key] !== oldValue[key]) {
|
|
42
|
-
keyDiffResults.changedKeys.add(key);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
delete keyDiffResults.sameKeys;
|
|
46
|
-
for (const key in keyDiffResults) {
|
|
47
|
-
if (keyDiffResults[key].size === 0) {
|
|
48
|
-
delete keyDiffResults[key];
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
if (Object.keys(keyDiffResults).length === 0 && window.RH_DEBUG_SKIP_EMPTY_CHANGE_EFFECTS) {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
} else {
|
|
55
|
-
if (isEqual(newValue, oldValue)) {
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
const debugArgs = [
|
|
60
|
-
{
|
|
61
|
-
effect: e.effect,
|
|
62
|
-
fn: e.effect.fn,
|
|
63
|
-
target: unref(e.target),
|
|
64
|
-
type: e.type,
|
|
65
|
-
key: e.key,
|
|
66
|
-
newValue,
|
|
67
|
-
oldValue,
|
|
68
|
-
oldTarget: unref(e.oldTarget),
|
|
69
|
-
},
|
|
70
|
-
];
|
|
71
|
-
if (keyDiffResults) {
|
|
72
|
-
debugArgs.push(keyDiffResults);
|
|
73
|
-
}
|
|
74
|
-
debugMessage(...debugArgs);
|
|
75
|
-
},
|
|
76
|
-
onRenderTracked: (debugMessage, e) => {
|
|
77
|
-
debugMessage({
|
|
78
|
-
fn: e.effect.fn,
|
|
79
|
-
target: unref(e.target),
|
|
80
|
-
type: e.type,
|
|
81
|
-
key: e.key,
|
|
82
|
-
});
|
|
83
|
-
},
|
|
84
|
-
};
|
|
85
|
-
const defaultHandler = (debugMessage) => {
|
|
86
|
-
debugMessage();
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Using useDebugMessage, log lifecycle events for the current component, with the specified categories.
|
|
91
|
-
* @function useLifecycleDebug
|
|
92
|
-
* @param {string[]} categories - the categories to give messages this generates
|
|
93
|
-
* @param {string[]} [includes] - the lifecycle functions to include
|
|
94
|
-
* @param {string[]} [excludes] - the lifecycle functions to exclude
|
|
95
|
-
*/
|
|
96
|
-
export function useLifecycleDebug(categories, includes = [], excludes = []) {
|
|
97
|
-
const lifeCycleFns = {
|
|
98
|
-
onActivated,
|
|
99
|
-
onBeforeMount,
|
|
100
|
-
onBeforeUnmount,
|
|
101
|
-
onBeforeUpdate,
|
|
102
|
-
onDeactivated,
|
|
103
|
-
onErrorCaptured,
|
|
104
|
-
onMounted,
|
|
105
|
-
onRenderTracked,
|
|
106
|
-
onRenderTriggered,
|
|
107
|
-
onServerPrefetch,
|
|
108
|
-
onUnmounted,
|
|
109
|
-
onUpdated,
|
|
110
|
-
};
|
|
111
|
-
const hasIncludes = includes && includes.length > 0;
|
|
112
|
-
const hasExcludes = excludes && excludes.length > 0;
|
|
113
|
-
for (const key in lifeCycleFns) {
|
|
114
|
-
if (hasIncludes && !includes.includes(key)) {
|
|
115
|
-
continue;
|
|
116
|
-
}
|
|
117
|
-
if (hasExcludes && excludes.includes(key)) {
|
|
118
|
-
continue;
|
|
119
|
-
}
|
|
120
|
-
const myCategories = new Set(categories);
|
|
121
|
-
myCategories.add("lifecycle");
|
|
122
|
-
myCategories.add(key);
|
|
123
|
-
const debugMessage = useDebugMessage(myCategories);
|
|
124
|
-
lifeCycleFns[key](partial(customHandlers[key] || defaultHandler, debugMessage));
|
|
125
|
-
}
|
|
126
|
-
}
|