fix: CRUD组件使用非严格比较导致部分场景query无法更新问题

This commit is contained in:
lurunze1226 2023-11-06 15:58:59 +08:00
parent 8af076ce0e
commit 7c951e3f75
2 changed files with 34 additions and 5 deletions

View File

@ -141,7 +141,32 @@ export const CRUDStore = ServiceStore.named('CRUDStore')
...values
};
if (isObjectShallowModified(originQuery, query, false)) {
/**
* CASE
* @reference https://tc39.es/ecma262/#sec-islooselyequal
*/
const exceptedLooselyRules: [any, any][] = [
[0, ''],
[false, ''],
[false, '0'],
[false, 0],
[true, 1],
[true, '1']
];
if (
isObjectShallowModified(originQuery, query, (lhs: any, rhs: any) => {
if (
exceptedLooselyRules.some(
rule => rule.includes(lhs) && rule.includes(rhs)
)
) {
return lhs === rhs;
}
return lhs == rhs;
})
) {
if (query[pageField || 'page']) {
self.page = parseInt(query[pageField || 'page'], 10);
}

View File

@ -251,7 +251,7 @@ export function rmUndefined(obj: PlainObject) {
export function isObjectShallowModified(
prev: any,
next: any,
strictMode: boolean = true,
strictModeOrFunc: boolean | ((lhs: any, rhs: any) => boolean) = true,
ignoreUndefined: boolean = false,
statck: Array<any> = []
): boolean {
@ -262,7 +262,7 @@ export function isObjectShallowModified(
isObjectShallowModified(
prev,
next[index],
strictMode,
strictModeOrFunc,
ignoreUndefined,
statck
)
@ -281,7 +281,11 @@ export function isObjectShallowModified(
isObservable(prev) ||
isObservable(next)
) {
return strictMode ? prev !== next : prev != next;
if (strictModeOrFunc && typeof strictModeOrFunc === 'function') {
return strictModeOrFunc(prev, next);
}
return strictModeOrFunc ? prev !== next : prev != next;
}
if (ignoreUndefined) {
@ -311,7 +315,7 @@ export function isObjectShallowModified(
isObjectShallowModified(
prev[key],
next[key],
strictMode,
strictModeOrFunc,
ignoreUndefined,
statck
)