Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8bae1db

Browse files
Merge pull request hilongjw#248 from biluochun/master
add types
2 parents 7e32a39 + e966fba commit 8bae1db

File tree

6 files changed

+129
-1
lines changed

6 files changed

+129
-1
lines changed

‎package.json‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
"build": "node build",
99
"lint": "eslint ./src",
1010
"test": "karma start",
11+
"test:types": "tsc -p types/test",
1112
"test:debug": "cross-env DEBUG=true karma start"
1213
},
1314
"dependencies": {},
1415
"repository": {
1516
"type": "git",
1617
"url": "https://github.com/hilongjw/vue-lazyload.git"
1718
},
19+
"typings": "types/index.d.ts",
1820
"keywords": [
1921
"vue-lazyload",
2022
"vue",
@@ -62,6 +64,6 @@
6264
"rollup-plugin-node-resolve": "^3.2.0",
6365
"rollup-plugin-replace": "^2.0.0",
6466
"rollup-plugin-uglify": "^1.0.1",
65-
"vue": "^2.5.13"
67+
"vue": "^2.5.16"
6668
}
6769
}

‎types/index.d.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import "./vue";
2+
import { VueLazyloadPluginObject } from "./lazyload";
3+
4+
declare var VueLazyload: VueLazyloadPluginObject;
5+
export default VueLazyload;
6+
7+
export {
8+
VueLazyloadImage,
9+
VueLazyloadOptions,
10+
VueLazyloadHandler,
11+
VueReactiveListener
12+
} from "./lazyload";

‎types/lazyload.d.ts‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { PluginObject } from "vue";
2+
3+
interface IntersectionObserverInit {
4+
root?: Element | null;
5+
rootMargin?: string;
6+
threshold?: number | number[];
7+
}
8+
9+
export interface VueLazyloadImage {
10+
src: string;
11+
error?: string;
12+
loading?: string;
13+
}
14+
15+
export interface VueLazyloadOptions {
16+
lazyComponent?: boolean;
17+
preLoad?: number;
18+
error?: string;
19+
loading?: string;
20+
attempt?: number;
21+
listenEvents?: string[];
22+
adapter?: any;
23+
filter?: any;
24+
dispatchEvent?: boolean;
25+
throttleWait?: number;
26+
observer?: boolean;
27+
observerOptions?: IntersectionObserverInit;
28+
silent?: boolean;
29+
preLoadTop?: number;
30+
scale?: number;
31+
hasbind?: boolean;
32+
}
33+
34+
export interface VueReactiveListener {
35+
el: Element;
36+
src: string;
37+
error: string;
38+
loading: string;
39+
bindType: string;
40+
attempt: number;
41+
naturalHeight: number;
42+
naturalWidth: number;
43+
options: VueLazyloadOptions;
44+
rect: DOMRect;
45+
$parent: Element
46+
elRenderer: Function;
47+
performanceData: {
48+
init: number,
49+
loadStart: number,
50+
loadEnd: number
51+
};
52+
}
53+
54+
export interface VueLazyloadListenEvent {
55+
(listener: VueReactiveListener, cache: boolean) : void;
56+
}
57+
58+
export interface VueLazyloadHandler {
59+
$on (event: string, callback: VueLazyloadListenEvent): void;
60+
$once (event: string, callback: VueLazyloadListenEvent): void;
61+
$off (event: string, callback?: VueLazyloadListenEvent): void;
62+
lazyLoadHandler (): void;
63+
}
64+
65+
export interface VueLazyloadPluginObject extends PluginObject<VueLazyloadOptions> {}

‎types/test/index.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import Vue from "vue";
2+
import VueLazyload, { VueLazyloadOptions } from "../index";
3+
4+
Vue.use<VueLazyloadOptions>(VueLazyload);
5+
6+
Vue.use<VueLazyloadOptions>(VueLazyload, {
7+
preLoad: 0,
8+
});
9+
10+
const vm = new Vue({});
11+
12+
vm.$Lazyload.lazyLoadHandler();
13+
vm.$Lazyload.$on('loading', function (state, cache) {
14+
const err: string = state.error;
15+
const el: Element = state.el;
16+
const bol: boolean = cache;
17+
});

‎types/test/tsconfig.json‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es5",
4+
"module": "es2015",
5+
"moduleResolution": "node",
6+
"lib": [
7+
"es5",
8+
"dom",
9+
"es2015.promise",
10+
"es2015.core"
11+
],
12+
"strict": true,
13+
"noEmit": true
14+
},
15+
"include": [
16+
"*.ts",
17+
"../*.d.ts"
18+
]
19+
}

‎types/vue.d.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Augment the typings of Vue.js
3+
*/
4+
5+
import Vue from "vue";
6+
import { VueLazyloadHandler } from "./index";
7+
8+
declare module "vue/types/vue" {
9+
interface Vue {
10+
$Lazyload: VueLazyloadHandler;
11+
}
12+
}
13+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /