mirror of
https://github.com/smartxworks/sunmao-ui.git
synced 2025-04-06 21:40:23 +08:00
chore(shared): move shallowCompare to object.ts
This commit is contained in:
parent
9cfb133adc
commit
ea65948c6c
@ -1,4 +1,4 @@
|
||||
import { shallowCompare } from '../src/utils/shallowCompare';
|
||||
import { shallowCompare } from '../src/utils';
|
||||
|
||||
describe('shallowCompare function', () => {
|
||||
it('compare values', () => {
|
||||
|
@ -1,4 +1,3 @@
|
||||
export * from './shallowCompare';
|
||||
export * from './number';
|
||||
export * from './spec';
|
||||
export * from './expression';
|
||||
|
@ -27,3 +27,18 @@ export function traverse(value: unknown, seen: Set<unknown> = new Set()) {
|
||||
export function isPromise(value: object): value is Promise<unknown> {
|
||||
return value instanceof Promise;
|
||||
}
|
||||
|
||||
export function shallowCompare(obj1: any, obj2: any) {
|
||||
if (typeof obj1 === 'object' && typeof obj2 === 'object') {
|
||||
if (Object.keys(obj1).length !== Object.keys(obj2).length) return false;
|
||||
for (const key in obj1) {
|
||||
if (key in obj2 && obj1[key] === obj2[key]) {
|
||||
continue;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return obj1 === obj2;
|
||||
}
|
||||
|
@ -1,14 +0,0 @@
|
||||
export function shallowCompare(obj1: any, obj2: any) {
|
||||
if (typeof obj1 === 'object' && typeof obj2 === 'object') {
|
||||
if (Object.keys(obj1).length !== Object.keys(obj2).length) return false;
|
||||
for (const key in obj1) {
|
||||
if (key in obj2 && obj1[key] === obj2[key]) {
|
||||
continue;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return obj1 === obj2;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user