Skip to content

Commit 77cd743

Browse files
committed
fix: afterLoad type
1 parent d9f522d commit 77cd743

12 files changed

+24
-74
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module.exports = {
1010
sourceType: 'module',
1111
},
1212
rules: {
13+
"prettier/prettier": 0,
1314
"@typescript-eslint/explicit-function-return-type": 0,
1415
},
1516
overrides: [

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
{
22
"name": "vue-lazy-load-image-component",
3-
"version": "0.0.7",
3+
"version": "0.0.8",
44
"description": "vue-lazy-load-image-component",
5-
"main": "lib/index.es.js",
5+
"main": "lib/index.js",
6+
"module": "lib/index.js",
7+
"types": "lib/index.d.ts",
68
"exports": {
7-
".": "./lib/index.es.js",
9+
".": "./lib/index.js",
810
"./lib/index.css": "./lib/index.css"
911
},
10-
"types": "./lib/index.d.ts",
1112
"scripts": {
1213
"dev": "vite",
1314
"build": "vite build",

src/components/LazyLoadImage.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ const LazyLoadImage = defineComponent({
1515
props: LazyLoadImagePropsFunc(),
1616
setup(props, { attrs }) {
1717
const loaded = ref(false);
18-
function onImageLoad() {
18+
function onImageLoad(): ((payload: Event) => void) | undefined {
1919
if (loaded.value) {
20-
return null;
20+
return undefined;
2121
}
22-
return () => {
23-
props.afterLoad?.();
22+
return (e) => {
23+
props.afterLoad?.(e);
2424
loaded.value = true;
2525
};
2626
}
@@ -47,8 +47,9 @@ const LazyLoadImage = defineComponent({
4747
} = props;
4848
return imgProps;
4949
});
50-
// @ts-ignore
51-
return <img onLoad={onImageLoad()} {...imgProps.value} {...attrs} />;
50+
return (
51+
<img onLoad={onImageLoad()} onError={props.onImageError} {...imgProps.value} {...attrs} />
52+
);
5253
}
5354
function getLazyLoadImage() {
5455
return (
@@ -80,7 +81,7 @@ const LazyLoadImage = defineComponent({
8081
backgroundSize: '100% 100%',
8182
};
8283
});
83-
function getWrappedLazyLoadImage(lazyLoadImage: any) {
84+
function getWrappedLazyLoadImage(lazyLoadImage: ReturnType<typeof getLazyLoadImage>) {
8485
return (
8586
<span
8687
class={

src/components/PlaceholderWithTracking.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import { trackWindowScroll } from './trackWindowScroll.tsx';
33
import PlaceholderWithoutTracking from './PlaceholderWithoutTracking';
44
import { PlaceholderWithTrackingPropsFunc } from './interface.ts';
55
const PlaceholderWithTracking = defineComponent({
6+
compatConfig: { MODE: 3 },
67
name: 'PlaceholderWithTracking',
8+
inheritAttrs: false,
79
props: PlaceholderWithTrackingPropsFunc(),
810
setup(props) {
911
return () => <PlaceholderWithoutTracking {...props} />;

src/components/PlaceholderWithoutTracking.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export default defineComponent({
7777
width: `${props.width}px`,
7878
};
7979
});
80+
console.log('props', props);
8081

8182
return () => {
8283
return (

src/components/__test__/LazyLoadComponent.test.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/components/__test__/LazyLoadImage.test.ts

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/components/__test__/__snapshots__/LazyLoadComponent.test.ts.snap

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/components/__test__/__snapshots__/LazyLoadImage.test.ts.snap

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/components/interface.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export interface ScrollPosition {
77
}
88
export const LazyLoadComponentPropsFunc = () => ({
99
afterLoad: {
10-
type: Function as PropType<() => void>,
10+
type: Function as PropType<(payload?: Event) => void>,
1111
default: () => {},
1212
},
1313
beforeLoad: {
@@ -64,6 +64,10 @@ export type Effect = 'blur' | 'black-and-white' | 'opacity';
6464
export const LazyLoadImagePropsFunc = () => {
6565
return {
6666
...LazyLoadComponentPropsFunc(),
67+
onImageError: {
68+
type: Function as PropType<(payload: Event) => void>,
69+
default: () => {},
70+
},
6771
effect: {
6872
type: String as PropType<Effect>,
6973
default: '',

0 commit comments

Comments
 (0)