记住
这是提供 memoize 函数,以及类型脚本
装饰器将 记住 一个阶级方法.
使用量
import memoize from '@github/memoize'
const fn = memoize(function doExpensiveStuff() {
// Here's where you do expensive stuff!
})
const other = memoize(function doExpensiveStuff() {}, {
cache: new Map(), // pass your own cache implementation
hash: JSON.stringify // pass your own hashing implementation
})
选项 :
hash?: (...args: A) => unknown提供单个值作为纪念的密钥. 默认为JSON.stringify(英语).cache?: Map<unknown, R>要提供的缓存执行 。 一定是地图还是地图 默认为地图 . 用 LRU 缓存或类似的缓存替换缓存有用 .
TypeScript 装饰器支持 !
这个包还包括一个可以用来提供 类型脚本装饰器 功能说明.
这是一个例子,显示你需要做什么:
import memoize from '@github/memoize/decorator'
// ^ note: add `/decorator` to the import to get decorators
class MyClass {
@memoize() // Memoize the method below
doThings() {
}
}
const cache = new Map()
class MyClass {
@memoize({ cache }) // Pass options just like the memoize function
doThings() {
}
}
为什么不用X包?
有许多内容被记住。 这个能提供我们需要的所有用途 GitHub 图像 并且没有更多的。 我们过去用过几次不同的执行, 这里有一些好的:
发展
npm install
npm test
许可证
以麻省理工学院许可证分发。 详情见LICENSE.