Skip to content

Commit 18e65ec

Browse files
author
jack
committed
添加typescript支持
1 parent b3b0071 commit 18e65ec

File tree

4 files changed

+56
-4
lines changed

4 files changed

+56
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.idea
22
.DS_Store
33
package-lock.json
4+
yarn.lock
45

56
logs
67
*.log

src/index.d.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
declare namespace recycleContext {
2+
interface itemSize {
3+
width: number;
4+
height: number;
5+
}
6+
7+
type Component = any;
8+
type Page = any;
9+
10+
type itemSizeFunc<T> = (item: T, index: number) => void
11+
12+
interface options<T> {
13+
id: string;
14+
dataKey: string;
15+
page: Component | Page;
16+
itemSize: itemSizeFunc<T> | itemSize;
17+
useInPage?: boolean;
18+
root?: Page;
19+
}
20+
21+
interface position {
22+
left: number;
23+
top: number;
24+
width: number;
25+
height: number;
26+
}
27+
28+
interface RecycleContext<T> {
29+
append(list: T[], callback?: () => void): void
30+
appendList(list: T[], callback?: () => void): void
31+
splice(begin: number, deleteCount: number, appendList: T[], callback?: () => void): void;
32+
updateList(beginIndex: number, list: T[], callback?: () => void): void
33+
update(beginIndex: number, list: T[], callback?: () => void): void
34+
destroy(): void
35+
forceUpdate(callback: () => void, reinitSlot: boolean): void
36+
getBoundingClientRect(index: number | undefined): position | position[]
37+
getScrollTop(): number;
38+
transformRpx(rpx: number, addPxSuffix?: string): number;
39+
getViewportItems(inViewportPx: number): T[]
40+
getList(): T[]
41+
}
42+
}
43+
declare function recycleContext<T>(op: recycleContext.options<T>): recycleContext.RecycleContext<T>
44+
45+
export = recycleContext;

tools/build.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,16 @@ class BuildTask {
231231
/**
232232
* copy resources to dist folder
233233
*/
234-
gulp.task(`${id}-copy`, gulp.parallel(done => {
234+
gulp.task(`${id}-copy`, gulp.parallel(async done => {
235235
const copyList = this.copyList
236-
const copyFileList = copyList.map(dir => path.join(dir, '**/*.!(wxss)'))
237-
236+
const anAsyncFunction = async dir => {
237+
const isFileExist = await _.checkFileExists(path.join(srcPath, dir));
238+
if (!isFileExist){
239+
return path.join(dir, '**/*.!(wxss)')
240+
}
241+
return dir
242+
}
243+
const copyFileList = await Promise.all(copyList.map(item => anAsyncFunction(item)))
238244
if (copyFileList.length) return copy(copyFileList)
239245

240246
return done()

tools/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,5 @@ module.exports = {
6262
assetFilter: assetFilename => assetFilename.endsWith('.js')
6363
}
6464
},
65-
copy: ['./wxml', './wxss', './wxs', './images'],
65+
copy: ['./wxml', './wxss', './wxs', './images', './index.d.ts'],
6666
}

0 commit comments

Comments
 (0)