Skip to content

Commit

Permalink
Merge pull request #248 from biluochun/master
Browse files Browse the repository at this point in the history
add types
  • Loading branch information
hilongjw authored Apr 28, 2018
2 parents 7e32a39 + e966fba commit 8bae1db
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 1 deletion.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
"build": "node build",
"lint": "eslint ./src",
"test": "karma start",
"test:types": "tsc -p types/test",
"test:debug": "cross-env DEBUG=true karma start"
},
"dependencies": {},
"repository": {
"type": "git",
"url": "https://github.com/hilongjw/vue-lazyload.git"
},
"typings": "types/index.d.ts",
"keywords": [
"vue-lazyload",
"vue",
Expand Down Expand Up @@ -62,6 +64,6 @@
"rollup-plugin-node-resolve": "^3.2.0",
"rollup-plugin-replace": "^2.0.0",
"rollup-plugin-uglify": "^1.0.1",
"vue": "^2.5.13"
"vue": "^2.5.16"
}
}
12 changes: 12 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import "./vue";
import { VueLazyloadPluginObject } from "./lazyload";

declare var VueLazyload: VueLazyloadPluginObject;
export default VueLazyload;

export {
VueLazyloadImage,
VueLazyloadOptions,
VueLazyloadHandler,
VueReactiveListener
} from "./lazyload";
65 changes: 65 additions & 0 deletions types/lazyload.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { PluginObject } from "vue";

interface IntersectionObserverInit {
root?: Element | null;
rootMargin?: string;
threshold?: number | number[];
}

export interface VueLazyloadImage {
src: string;
error?: string;
loading?: string;
}

export interface VueLazyloadOptions {
lazyComponent?: boolean;
preLoad?: number;
error?: string;
loading?: string;
attempt?: number;
listenEvents?: string[];
adapter?: any;
filter?: any;
dispatchEvent?: boolean;
throttleWait?: number;
observer?: boolean;
observerOptions?: IntersectionObserverInit;
silent?: boolean;
preLoadTop?: number;
scale?: number;
hasbind?: boolean;
}

export interface VueReactiveListener {
el: Element;
src: string;
error: string;
loading: string;
bindType: string;
attempt: number;
naturalHeight: number;
naturalWidth: number;
options: VueLazyloadOptions;
rect: DOMRect;
$parent: Element
elRenderer: Function;
performanceData: {
init: number,
loadStart: number,
loadEnd: number
};
}

export interface VueLazyloadListenEvent {
(listener: VueReactiveListener, cache: boolean) : void;
}

export interface VueLazyloadHandler {
$on (event: string, callback: VueLazyloadListenEvent): void;
$once (event: string, callback: VueLazyloadListenEvent): void;
$off (event: string, callback?: VueLazyloadListenEvent): void;
lazyLoadHandler (): void;
}

export interface VueLazyloadPluginObject extends PluginObject<VueLazyloadOptions> {}
17 changes: 17 additions & 0 deletions types/test/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import Vue from "vue";
import VueLazyload, { VueLazyloadOptions } from "../index";

Vue.use<VueLazyloadOptions>(VueLazyload);

Vue.use<VueLazyloadOptions>(VueLazyload, {
preLoad: 0,
});

const vm = new Vue({});

vm.$Lazyload.lazyLoadHandler();
vm.$Lazyload.$on('loading', function (state, cache) {
const err: string = state.error;
const el: Element = state.el;
const bol: boolean = cache;
});
19 changes: 19 additions & 0 deletions types/test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"target": "es5",
"module": "es2015",
"moduleResolution": "node",
"lib": [
"es5",
"dom",
"es2015.promise",
"es2015.core"
],
"strict": true,
"noEmit": true
},
"include": [
"*.ts",
"../*.d.ts"
]
}
13 changes: 13 additions & 0 deletions types/vue.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Augment the typings of Vue.js
*/

import Vue from "vue";
import { VueLazyloadHandler } from "./index";

declare module "vue/types/vue" {
interface Vue {
$Lazyload: VueLazyloadHandler;
}
}

0 comments on commit 8bae1db

Please sign in to comment.