Skip to content

Commit 807ca70

Browse files
BuptStEveevinma
authored andcommitted
refactor: remove $
1 parent 0bf491f commit 807ca70

File tree

3 files changed

+4
-13
lines changed

3 files changed

+4
-13
lines changed

src/index.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {
2-
$,
32
isServer,
43
detectOS,
54
getEventListenerOptions,
@@ -19,9 +18,9 @@ const lockedElements: HTMLElement[] = []
1918
const eventListenerOptions = getEventListenerOptions({ passive: false })
2019

2120
const setOverflowHiddenPc = () => {
22-
const $body = $('body')
21+
const $body = document.body
2322
const bodyStyle = { ...$body.style }
24-
const scrollBarWidth = window.innerWidth - document.body.clientWidth
23+
const scrollBarWidth = window.innerWidth - $body.clientWidth
2524

2625
$body.style.overflow = 'hidden'
2726
$body.style.boxSizing = 'border-box'
@@ -35,8 +34,8 @@ const setOverflowHiddenPc = () => {
3534
}
3635

3736
const setOverflowHiddenMobile = () => {
38-
const $html = $('html')
39-
const $body = $('body')
37+
const $html = document.documentElement
38+
const $body = document.body
4039
const scrollTop = $html.scrollTop || $body.scrollTop
4140
const htmlStyle = { ...$html.style }
4241
const bodyStyle = { ...$body.style }

src/utils.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
export const isServer = () => typeof window === 'undefined'
22

3-
export const $ = (selector: string) => <HTMLElement>document.querySelector(selector)
4-
53
export interface DetectOSResult { ios: boolean, android: boolean }
64
export const detectOS = (ua?: string): DetectOSResult => {
75
ua = ua || navigator.userAgent

test/utils.test.ts

-6
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,12 @@
22
* @jest-environment jsdom-thirteen
33
*/
44
import {
5-
$,
65
isServer,
76
detectOS,
87
getEventListenerOptions,
98
} from '@/utils'
109

1110
describe('utils', () => {
12-
13-
it('$', () => {
14-
expect($('body').tagName).toBe('BODY')
15-
})
16-
1711
it(`should detect server`, () => {
1812
expect(isServer()).toBe(false)
1913
})

0 commit comments

Comments
 (0)