Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(utils): adjust the order of getting self #178

Merged
merged 3 commits into from
Jul 18, 2019
Merged
Changes from 2 commits
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
9 changes: 5 additions & 4 deletions packages/utils/src/clone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { isFn } from '@uform/types'

type Filter = (value: any, key: string) => boolean

const self: { [key: string]: any } = this || global || window
const _self: { [key: string]: any } =
self || window || global || Function('return this')()

const NATIVE_KEYS = [
Copy link
Contributor

@stkevintan stkevintan Jul 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NATIVE_KEYS: [string, (obj: any) => any][] = [xxxx]

下面就不用as了

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好像这样子也是不行的哦,他是有 string 类型的

NATIVE_KEYS: ([string, (obj: any) => any] | string)[] = [xxxx]

这样子解有点问题,下面去掉 as string ,也是会报错。

['Map', (map: any) => new Map(map)],
Expand All @@ -26,13 +27,13 @@ const isNativeObject = (values: any): any => {
const item = NATIVE_KEYS[i]
if (Array.isArray(item) && item[0]) {
if (
self[item[0] as string] &&
values instanceof self[item[0] as string]
_self[item[0] as string] &&
values instanceof _self[item[0] as string]
) {
return item[1] ? item[1] : item[0]
}
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else if

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是在哪里的 else if 呢?

if (self[item as string] && values instanceof self[item as string]) {
if (_self[item as string] && values instanceof _self[item as string]) {
return item
}
}
Expand Down