Skip to content

Commit

Permalink
feat(shared): support BigNumber (#4182)
Browse files Browse the repository at this point in the history
Co-authored-by: zishaofei <[email protected]>
  • Loading branch information
ShaofeiZi and zishaofei authored Jul 16, 2024
1 parent 37d437d commit b46b9b7
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
61 changes: 61 additions & 0 deletions packages/shared/src/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,9 @@ describe('clone and compare', () => {
$$typeof: true,
_owner: true,
},
dd: {
_isBigNumber: true,
},
})
).toEqual({
aa: {
Expand All @@ -326,6 +329,9 @@ describe('clone and compare', () => {
$$typeof: true,
_owner: true,
},
dd: {
_isBigNumber: true,
},
})
expect(
clone({
Expand Down Expand Up @@ -377,6 +383,13 @@ describe('clone and compare', () => {
expect(shallowClone({ _isAMomentObject: true })).toEqual({
_isAMomentObject: true,
})
expect(
shallowClone({
_isBigNumber: true,
})
).toEqual({
_isBigNumber: true,
})
expect(
shallowClone({
_isJSONSchemaObject: true,
Expand Down Expand Up @@ -714,6 +727,36 @@ describe('merge', () => {
bb: 321,
},
})
expect(
merge(
{
react: {
_isBigNumber: true,
c: [1, 234567890123],
e: 0,
s: 1,
},
},
{
react: {
_isBigNumber: true,
c: [2, 345678901234],
e: 1,
s: 0,
},
},
{
assign: true,
}
)
).toEqual({
react: {
_isBigNumber: true,
c: [2, 345678901234],
e: 1,
s: 0,
},
})
const toJSObj = {
toJS: () => {},
bb: 321,
Expand Down Expand Up @@ -950,6 +993,10 @@ test('defaults', () => {
ee: {
toJS,
},
ff: {
_isBigNumber: true,
toJSON,
},
},
{
aa: { value: 111 },
Expand All @@ -958,6 +1005,13 @@ test('defaults', () => {
dd: { value: 444 },
ee: { value: 555 },
mm: { value: 123 },
ff: {
value: {
c: [1, 234567890123],
e: 0,
s: 1,
},
},
}
)
).toEqual({
Expand All @@ -967,6 +1021,13 @@ test('defaults', () => {
dd: { value: 444 },
ee: { value: 555 },
mm: { value: 123 },
ff: {
value: {
c: [1, 234567890123],
e: 0,
s: 1,
},
},
})

expect(defaults([1, 2, 3], [0, undefined])).toEqual([0, 2, 3])
Expand Down
6 changes: 6 additions & 0 deletions packages/shared/src/clone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ export const shallowClone = (values: any) => {
if ('$$typeof' in values && '_owner' in values) {
return values
}
if (values['_isBigNumber']) {
return values
}
if (values['_isAMomentObject']) {
return values
}
Expand Down Expand Up @@ -39,6 +42,9 @@ export const clone = (values: any) => {
if ('$$typeof' in values && '_owner' in values) {
return values
}
if (values['_isBigNumber']) {
return values
}
if (values['_isAMomentObject']) {
return values
}
Expand Down

0 comments on commit b46b9b7

Please sign in to comment.