Skip to content

Commit a982924

Browse files
committed
feat: type
1 parent a944b8f commit a982924

File tree

7 files changed

+104
-112
lines changed

7 files changed

+104
-112
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"vite": "^4.3.5",
3232
"vite-plugin-dts": "^2.3.0",
3333
"vue": "^3.3.2",
34-
"vue-lazy-load-image-component": "0.0.3"
34+
"vue-lazy-load-image-component": "0.0.4"
3535
},
3636
"devDependencies": {
3737
"@types/jest": "^29.5.1",

pnpm-lock.yaml

Lines changed: 26 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/LazyLoadComponent.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { DefineComponent } from 'vue'
12
import { reactive, computed, watch, defineComponent, ExtractPropTypes } from 'vue'
23
import PlaceholderWithoutTracking from './PlaceholderWithoutTracking.tsx'
34
import isIntersectionObserverAvailable from '../utils/intersection-observer';
@@ -70,5 +71,5 @@ export default defineComponent({
7071
/>
7172
}
7273
}
73-
})
74+
}) as DefineComponent<LazyLoadComponentProps>
7475

src/components/PlaceholderWithTracking.tsx

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,13 @@
1-
import { PropType, defineComponent } from 'vue'
1+
import { defineComponent } from 'vue'
22
import { trackWindowScroll } from './trackWindowScroll.tsx'
33
import PlaceholderWithoutTracking from './PlaceholderWithoutTracking'
4-
import { ScrollPosition, VueNode } from './interface.ts'
4+
import { PlaceholderWithTrackingPropsFunc } from './interface.ts'
55
const PlaceholderWithTracking = defineComponent({
66
name: 'PlaceholderWithTracking',
7-
props: {
8-
scrollPosition: {
9-
type: Object as PropType<ScrollPosition>,
10-
default: null
11-
},
12-
useIntersectionObserver: {
13-
type: Boolean,
14-
default: true
15-
},
16-
threshold: {
17-
type: Number,
18-
default: 300
19-
},
20-
onVisible: {
21-
type: Function as PropType<() => void>,
22-
default: () => { }
23-
},
24-
height: {
25-
type: Number,
26-
default: 0
27-
},
28-
width: {
29-
type: Number,
30-
default: 0
31-
},
32-
placeholder:{
33-
type: Object as PropType<VueNode>,
34-
default: () => { }
35-
}
36-
},
37-
setup(props, { attrs }) {
7+
props: PlaceholderWithTrackingPropsFunc(),
8+
setup(props) {
389
return () => (
39-
<PlaceholderWithoutTracking {...props} {...attrs} />
10+
<PlaceholderWithoutTracking {...props} />
4011
)
4112
}
4213
})

src/components/PlaceholderWithoutTracking.tsx

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,13 @@
1-
import type { PropType } from 'vue'
1+
import type { DefineComponent } from 'vue'
22
import { computed, onMounted, shallowRef, defineComponent } from 'vue'
33

44
import isIntersectionObserverAvailable from '../utils/intersection-observer'
55
import { getObserver } from '../utils'
6-
import { ScrollPosition, VueNode } from './interface'
6+
import { PlaceholderWithoutTrackingPropsFunc } from './interface'
77

88
export default defineComponent({
99
name: 'PlaceholderWithoutTracking',
10-
props: {
11-
scrollPosition: {
12-
type: Object as PropType<ScrollPosition>,
13-
default: null
14-
},
15-
useIntersectionObserver: {
16-
type: Boolean,
17-
default: true
18-
},
19-
threshold: {
20-
type: Number,
21-
default: 300
22-
},
23-
onVisible: {
24-
type: Function as PropType<() => void>,
25-
default: () => { }
26-
},
27-
height: {
28-
type: Number,
29-
default: 0
30-
},
31-
width: {
32-
type: Number,
33-
default: 0
34-
},
35-
placeholder: {
36-
type: Object as PropType<VueNode>,
37-
default: () => { }
38-
}
39-
},
10+
props: PlaceholderWithoutTrackingPropsFunc(),
4011
setup(props) {
4112
const placeholder = shallowRef<HTMLElement>()
4213
const supportsObserver = computed(() => !props.scrollPosition &&
@@ -117,4 +88,4 @@ export default defineComponent({
11788
)
11889
}
11990
}
120-
})
91+
}) as DefineComponent<ReturnType<typeof PlaceholderWithoutTrackingPropsFunc>>

src/components/interface.ts

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export const LazyLoadComponentPropsFunc = () => ({
3939
default: 300
4040
},
4141
style: {
42-
type: Object as PropType<CSSProperties>,
42+
type: Object as PropType<Partial<CSSProperties>>,
4343
default: () => { }
4444
},
4545
class: {
@@ -88,3 +88,66 @@ export const LazyLoadImagePropsFunc = () => {
8888
},
8989
}
9090
}
91+
92+
export const PlaceholderWithoutTrackingPropsFunc = () => ({
93+
scrollPosition: {
94+
type: Object as PropType<ScrollPosition>,
95+
default: null
96+
},
97+
useIntersectionObserver: {
98+
type: Boolean,
99+
default: true
100+
},
101+
threshold: {
102+
type: Number,
103+
default: 300
104+
},
105+
onVisible: {
106+
type: Function as PropType<() => void>,
107+
default: () => { }
108+
},
109+
height: {
110+
type: Number,
111+
default: 100
112+
},
113+
width: {
114+
type: Number,
115+
default: 100
116+
},
117+
placeholder: {
118+
type: Object as PropType<VueNode>,
119+
default: () => { }
120+
}
121+
})
122+
123+
124+
export const PlaceholderWithTrackingPropsFunc = () => ({
125+
scrollPosition: {
126+
type: Object as PropType<ScrollPosition>,
127+
default: null
128+
},
129+
useIntersectionObserver: {
130+
type: Boolean,
131+
default: true
132+
},
133+
threshold: {
134+
type: Number,
135+
default: 300
136+
},
137+
onVisible: {
138+
type: Function as PropType<() => void>,
139+
default: () => { }
140+
},
141+
height: {
142+
type: Number,
143+
default: 0
144+
},
145+
width: {
146+
type: Number,
147+
default: 0
148+
},
149+
placeholder: {
150+
type: Object as PropType<VueNode>,
151+
default: () => { }
152+
}
153+
})

src/components/trackWindowScroll.tsx

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,16 @@
1-
import type { PropType } from 'vue'
21
import { computed, defineComponent, onMounted, reactive, shallowRef, watch, onBeforeUnmount } from "vue";
32
import { debounce, throttle } from 'lodash-es';
43
import isIntersectionObserverAvailable from '../utils/intersection-observer';
54
import getScrollAncestor from '../utils/get-scroll-ancestor';
65
import { getScrollX, getScrollY } from "../utils";
7-
import { ScrollPosition, VueNode } from "./interface";
6+
import { LazyLoadComponentPropsFunc } from './interface';
87

98
export type TrackWindowScroll = (Component: ReturnType<typeof defineComponent>) => ReturnType<typeof defineComponent>
109

1110
export const trackWindowScroll: TrackWindowScroll = (Component) => {
1211
const ScrollAwareComponent = defineComponent({
1312
name: "ScrollAwareComponent",
14-
props: {
15-
scrollPosition: {
16-
type: Object as PropType<ScrollPosition>,
17-
default: null
18-
},
19-
useIntersectionObserver: {
20-
type: Boolean,
21-
default: true
22-
},
23-
threshold: {
24-
type: Number,
25-
default: 300
26-
},
27-
onVisible: {
28-
type: Function as PropType<() => void>,
29-
default: () => { }
30-
},
31-
height: {
32-
type: Number,
33-
default: 0
34-
},
35-
width: {
36-
type: Number,
37-
default: 0
38-
},
39-
delayMethod: {
40-
type: String as PropType<'debounce' | 'throttle'>,
41-
default: 'throttle'
42-
},
43-
delayTime: {
44-
type: Number,
45-
default: 300
46-
},
47-
placeholder: {
48-
type: Object as PropType<VueNode>,
49-
default: () => { }
50-
}
51-
},
13+
props: LazyLoadComponentPropsFunc(),
5214
setup(props, { attrs }) {
5315
const useIntersectionObserver = computed(() => props.useIntersectionObserver && isIntersectionObserverAvailable())
5416
const baseComponentRef = shallowRef(null)

0 commit comments

Comments
 (0)