import React, { Component, useCallback, useRef, useState } from 'react'
import { View, Text, Button } from '@tarojs/components'
import VirtualList from '@tarojs/components/virtual-list'
function buildData(offset = 0) {
return Array(100)
.fill(0)
.map((_, i) => i + offset)
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/ts-node | |
| const SymbolCache = Symbol.for("cache"); | |
| let miss = 0; | |
| function computed(...args) { | |
| const _cache = {}; | |
| return function ( | |
| target, | |
| propertyKey: string, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| interface Test<T> { | |
| g?: Test<T>; | |
| } | |
| function mixinPerson<T extends Constructor<{}>>(Base: T) { | |
| return class Base { | |
| constructor(public name: string) { } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const doThis = count => Array.prototype.map.bind(Array.from({ length: count })); | |
| export const Timeout = (timeout, promise?: Promise<any>) => | |
| new Promise((resolve, reject) => { | |
| const timer = setTimeout(() => { | |
| reject(new Error(`Timeout(${timeout})`)); | |
| }, timeout); | |
| // 如果完成了得清理 | |
| const clear = () => clearTimeout(timer); | |
| promise.then(clear, clear); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import replace from '@rollup/plugin-replace'; | |
| let manifest = {}; | |
| export const replaceManifest = () => { | |
| return replace({ | |
| __MANIFEST__: () => JSON.stringify(manifest), | |
| }); | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| name: 'InlineScriptHTMLRender', | |
| async generateBundle(_, bundles, isWrite) { | |
| if (isWrite) { | |
| return new Promise((resolve) => { | |
| Object.values(bundles).map((bundle) => { | |
| Object.keys(bundles).map(key => delete bundles[key]); | |
| if (bundle.name === 'bootloader') { | |
| renderFile('src/index.ejs', { | |
| inlineScript: bundle.code, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import byteSize from 'byte-size'; | |
| const manifest = []; | |
| process.on('beforeExit', () => { | |
| console.table(manifest); | |
| }); | |
| export default () => ({ | |
| name: 'Size', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # only-dev && only execute in dev env and throw an error in other | |
| # only-dev || only execute in non-dev env and do nothing in other | |
| if [[ $NODE_ENV =~ ^dev ]] | |
| then | |
| exit 0 | |
| fi | |
| exit -1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function InvertedPromise() { | |
| let _ = undefined; | |
| return Object.assign(new Promise((resolve, reject) => { _ = { 0: resolve, 1: reject, resolve, reject } }), _); | |
| } | |
| function InvertedPromise() { | |
| let _ = undefined; | |
| return _ = new Promise((resolve, reject) => | |
| Promise.resolve() | |
| .then(() => Object.assign(_, { resolve, reject }))); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const useForceUpdate = () => Object.assign.apply(null, useReducer(({ current }) => ({ current: current + 1 }), { current: 0 }).reverse()); | |
| functioin Test() { | |
| const forceUpdate = useForceUpdate(); | |
| const dataMap = useMemo(() => new WeakMap(), [forceUpdate.current]); | |
| } |