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: useDebounce 在小程序里使用问题 #1472

Merged
merged 7 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion packages/hooks/src/useDebounceFn/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import debounce from 'lodash/debounce';
import { debounce } from '../utils/lodash-polyfill';
import { useMemo } from 'react';
import type { DebounceOptions } from '../useDebounce/debounceOptions';
import useLatest from '../useLatest';
Expand Down
17 changes: 17 additions & 0 deletions packages/hooks/src/utils/lodash-polyfill.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import debounce from 'lodash/debounce';

function isNodeOrWeb() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

if(!global.Date) {
  global.Date = Date
}

如果是上面这样呢?会有啥区别?

NervJS/taro#8098 (comment)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

感觉跟这个处理方法是一样的,都是为了把 原生对象挂到 global 里

var freeGlobal =
(typeof global === 'undefined' ? 'undefined' : typeof global) == 'object' &&
global &&
global.Object === Object &&
global;
var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
return freeGlobal || freeSelf;
}

if (!isNodeOrWeb()) {
global.Date = Date;
}
liuyib marked this conversation as resolved.
Show resolved Hide resolved

export { debounce };