Skip to content

Commit

Permalink
perf: 升级TaroV3
Browse files Browse the repository at this point in the history
  • Loading branch information
Rahim-Chan committed Aug 14, 2020
1 parent 892de4d commit 8119eb9
Show file tree
Hide file tree
Showing 14 changed files with 89 additions and 104 deletions.
2 changes: 1 addition & 1 deletion config/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default {
}),
RollupJson(),
RollupTypescript({
tsconfig: resolveFile('tsconfig.rollup.json')
tsconfig: resolveFile('tsconfig.json')
}),
RollupCopy({
targets: [
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "taro-listview",
"version": "1.4.9",
"version": "1.4.3",
"description": "listView pullDownRefresh and skeleton",
"templateInfo": {
"name": "default",
Expand Down Expand Up @@ -38,7 +38,7 @@
"dev:tt": "npm run build:tt -- --watch",
"dev:h5": "npm run build:h5 -- --watch",
"dev:rn": "npm run build:rn -- --watch",
"build:lib": "tsc --project ./tsconfig.build.json",
"build:lib": "tsc --project ./tsconfig.json",
"build:rollup": "rollup --config ./config/rollup.config.js",
"copy": "node ./scripts/build.js",
"types": "tsc -d --emitDeclarationOnly --allowJs false --diagnostics --declarationDir ./@types",
Expand All @@ -47,7 +47,7 @@
},
"author": "rahim <chenrixi93@gmail.com>",
"publishConfig": {
"registry": "http://152.136.203.150:4873"
"registry": "https://registry.npmjs.org"
},
"repository": {
"type": "git",
Expand Down
38 changes: 35 additions & 3 deletions project.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"preloadBackgroundData": false,
"minified": false,
"newFeature": true,
"autoAudits": false,
"coverView": true,
"autoAudits": false,
"showShadowRootInWxmlPanel": true,
"scopeDataCheck": false,
"checkInvalidKey": true,
Expand All @@ -22,11 +22,43 @@
"disablePlugins": [],
"outputPath": ""
},
"useCompilerModule": false
"useCompilerModule": false,
"userConfirmedUseCompilerModuleSwitch": false
},
"compileType": "miniprogram",
"simulatorType": "wechat",
"simulatorPluginLibVersion": {},
"libVersion": "2.10.4",
"condition": {}
"condition": {
"search": {
"current": -1,
"list": []
},
"conversation": {
"current": -1,
"list": []
},
"plugin": {
"current": -1,
"list": []
},
"game": {
"list": []
},
"gamePlugin": {
"current": -1,
"list": []
},
"miniprogram": {
"current": -1,
"list": [
{
"id": -1,
"name": "pages/index/index",
"pathName": "pages/index/index",
"scene": null
}
]
}
}
}
43 changes: 25 additions & 18 deletions src/components/list-view/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class ListView extends Component<Props, State> {
if (this.props.lazy) {
const { lazyStorage } = this.props;
return tools.lazyScrollInit(this.lazyClassName, lazyStorage)
} else {
return undefined
}
})();

Expand Down Expand Up @@ -206,28 +208,33 @@ class ListView extends Component<Props, State> {
}
};

updateDampText = act => {
updateDampText = (act: boolean) => {
this.needPullDown = act;
const { isInit, downLoading } = this.state;
const showTip = !downLoading && !isInit; // 展示下拉区域文案
if (!showTip) return "";
const { indicator = {}, tipFreedText, tipText } = this.props;
const {
activate = "释放刷新",
deactivate = "下拉刷新"
} = indicator as Indicator;
let text = "";
if (act) {
text = activate || tipText;
} else {
text = deactivate || tipFreedText;
}
if (Taro.getEnv() === "WEB") {
const target = document.getElementById(this.tipDampTextId) as HTMLElement;
target.innerText = text;
if (!showTip) {
return ''
} else {
this.setState({ dampText: text });
const { indicator = {}, tipFreedText, tipText } = this.props;
const {
activate = "释放刷新",
deactivate = "下拉刷新"
} = indicator as Indicator;
let text = "";
if (act) {
text = activate || tipText;
} else {
text = deactivate || tipFreedText;
}
if (Taro.getEnv() === "WEB") {
const target = document.getElementById(this.tipDampTextId) as HTMLElement;
target.innerText = text;
} else {
this.setState({ dampText: text });
}
return undefined
}

};

render() {
Expand Down Expand Up @@ -306,7 +313,7 @@ class ListView extends Component<Props, State> {
</View>
</View>
{/* present children */}
{/*{showChildren && this.props.children}*/}
{showChildren && this.props.children}
<ResultPage
renderError={this.props.renderError}
renderEmpty={this.props.renderEmpty}
Expand Down
4 changes: 3 additions & 1 deletion src/components/list-view/tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ interface LazyItem {
export function debounce(method, time = 500) {
let timer = null;
return function() {
const context = this;
// @ts-ignore
const context = this;
// 在函数执行的时候先清除timer定时器;
// @ts-ignore
clearTimeout(timer);
Expand All @@ -27,6 +28,7 @@ const throttle = function(func, delay) {
return function() {
const curTime = Date.now();
const remaining = delay - (curTime - startTime);
// @ts-ignore
const context = this;
const args = arguments;
// @ts-ignore
Expand Down
9 changes: 6 additions & 3 deletions src/components/virtual-list/hooks-list.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {Dispatch, SetStateAction, useCallback, useRef, useState} from '@tarojs/taro';
import {useCallback, useRef, useState} from 'react';
import diff from './diff';
import vr from './virtual'

interface Methods<S> {
append: Dispatch<SetStateAction<S>>
append: any
}
const screenNum = 7;
const screenPage = 3;
const moreNum = screenNum * screenPage;
let outSetList: Taro.Dispatch<Taro.SetStateAction<any[]>> = () => {};
let outSetList = () => {};
let updateList: (scrollTop) => void = () => {
};

Expand All @@ -23,6 +23,7 @@ const UseList = (initData: any[] | (() => any[])): [any[], Methods<any>] => {
const append = (newData) => {
pureList.current = list.concat(newData).map((i, y) => {
return {
// @ts-ignore
...i,
__index__: y,
bottom: (y + 1) * vr.height,
Expand All @@ -31,6 +32,7 @@ const UseList = (initData: any[] | (() => any[])): [any[], Methods<any>] => {
// setList(newList);
setTimeout(() => {
if (setHeightRef.current !== null) {
// @ts-ignore
setHeightRef.current(pureList.current.length * vr.height + 'px')
}
}, 300)
Expand All @@ -55,6 +57,7 @@ const UseList = (initData: any[] | (() => any[])): [any[], Methods<any>] => {
cacheList.current = showList
}, []);

// @ts-ignore
ctx.calcHeight = (setHeight) => {
setHeightRef.current = setHeight;
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/virtual-list/use-list.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useState, useCallback, useEffect, useRef} from '@tarojs/taro';
import {useState, useCallback, useEffect, useRef} from 'react';
import diff from './diff';

interface UTILS {
Expand Down Expand Up @@ -28,10 +28,10 @@ interface ListItem {

const UseList = (id: string) => {
const [renderList, setList] = useState<ListItem[]>([]);//render in viewpoint
const [isMount, setIsMount] = useState<boolean>(false);//render in viewpoint
const [, setIsMount] = useState<boolean>(false);//render in viewpoint
const totalHeight = useRef(0);//height of contain
const cacheList = useRef<ListItem[]>([]);//cache all data<ListItem[]>
const cacheScrollTop = useRef(0); //recode scrollTop of list
// const cacheScrollTop = useRef(0); //recode scrollTop of list
const cacheViewPointData = useRef({
beginIndex: 0,
endIndex: totalAmount,
Expand Down
5 changes: 3 additions & 2 deletions src/components/virtual-list/v2-list.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Taro, {useState, useEffect } from '@tarojs/taro';
import React, {useState, useEffect } from 'react';
import Taro from '@tarojs/taro';
import {View, ScrollView} from '@tarojs/components';
import {utils} from './use-list';
import { throttle } from "../../utils/utils";
Expand Down Expand Up @@ -45,7 +46,7 @@ const VirList: Taro.FunctionComponent<Props>= (props) => {
onScrollToLower={handleLower}
>
<View id='foo' className='recycleList' style={{ position:'relative', height: `${totalHeight}px` }}>
{this.props.children}
{props.children}
</View>
</ScrollView>
)
Expand Down
4 changes: 2 additions & 2 deletions src/pages/index/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default class Index extends Component {
customizeLoading
lazyStorage='listView'
>
{list.map((item, index) => {
{list.map((item: any, index) => {
return (
<View className='item skeleton-bg' key={`item_${index}`}>
<LazyBlock current={index} className='avatar' lazyStorage='listView'>
Expand Down Expand Up @@ -121,7 +121,7 @@ export default class Index extends Component {
customizeLoading
lazyStorage='listView'
>
{list.map((item, index) => {
{list.map((item: any, index) => {
return (
<View className='item skeleton-bg' key={`item_${index}`}>
<LazyBlock current={index} className='avatar' lazyStorage='listView'>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/index/lazy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default class Index extends Component {
onScrollToLower={this.onScrollToLower}
lazyStorage='listViewLazy'
>
{list.map((item, index) => {
{list.map((item: any, index) => {
return (
<View className='item' key={`item_${index}`}>
<LazyBlock current={index} className='avatar' lazyStorage='listViewLazy'>
Expand Down
10 changes: 5 additions & 5 deletions src/style/index.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@import './components/list-view/index.scss'
@import './components/list-view/block.scss'
@import './components/loading/index.scss'
@import './components/result-page/index.scss'
@import './components/skeleton/index.scss'
@import './components/list-view/index.scss';
@import './components/list-view/block.scss';
@import './components/loading/index.scss';
@import './components/result-page/index.scss';
@import './components/skeleton/index.scss';

28 changes: 0 additions & 28 deletions tsconfig.build.json

This file was deleted.

4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
},
"noImplicitAny": false
},
"include": ["./src"],
"exclude": ["node_modules", "scripts", "webpack", "jest"]
"include": ["src/**/*"],
"exclude": ["node_modules/*", "scripts", "webpack", "jest"]
}
32 changes: 0 additions & 32 deletions tsconfig.rollup.json

This file was deleted.

0 comments on commit 8119eb9

Please sign in to comment.