Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/shared/src/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import moment from 'moment'
import dayjs from 'dayjs'
import { Map as ImmutableMap } from 'immutable'
import { isEqual } from '../compare'
import {
Expand Down Expand Up @@ -374,6 +375,8 @@ describe('clone and compare', () => {
expect(clone(regexp) === regexp).toBeTruthy()
const promise = Promise.resolve(1)
expect(clone(promise) === promise).toBeTruthy()
const day = dayjs()
expect(clone(day).toISOString() === day.toISOString()).toBeTruthy()
})

test('shallowClone', () => {
Expand Down
14 changes: 14 additions & 0 deletions packages/shared/src/clone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,18 @@ export const shallowClone = (values: any) => {
if (values['_isAMomentObject']) {
return values
}
if (values['$isDayjsObject']) {
return values
}
Comment thread
nanyuantingfeng marked this conversation as resolved.
if (values['_isJSONSchemaObject']) {
return values
}
if (isFn(values['toJS'])) {
return values
}
if (isFn(values['clone'])) {
return values['clone']()
}
if (isFn(values['toJSON'])) {
return values
}
Expand Down Expand Up @@ -48,12 +54,20 @@ export const clone = (values: any) => {
if (values['_isAMomentObject']) {
return values
}

if (values['$isDayjsObject']) {
return values
}

if (values['_isJSONSchemaObject']) {
return values
}
if (isFn(values['toJS'])) {
return values['toJS']()
}
if (isFn(values['clone'])) {
return values['clone']()
}
if (isFn(values['toJSON'])) {
return values['toJSON']()
}
Expand Down
Loading