npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

repure

v1.0.1

Published

给 **pure function** 添加记忆功能, 替代[reselect](https://github.com/reactjs/reselect.git)并且提供更加简单的写法。 对于**pure function** 相同的入参,会得到相同的结果。 所以repure会根据入参来缓存结果, 一旦发现 入参相同,就直接返回缓存的结果

Downloads

10

Readme

repure

pure function 添加记忆功能, 替代reselect并且提供更加简单的写法。 对于pure function 相同的入参,会得到相同的结果。 所以repure会根据入参来缓存结果, 一旦发现 入参相同,就直接返回缓存的结果

Get Start

install :npm install repure

import repure from 'repure'

function f(a, b) {
  console.log('invoke f, will takes 5 seconds')
  return a + b
}

const rf = repure(f)

rf(1, 1) // takes 5 seconds
rf(1, 1) // takes 0 seconds
rf(1, 1) // takes 0 seconds
rf(1, 1) // takes 0 seconds
rf(2, 2) // takes 5 seconds

API

repure 提供3个方法 repureCreator(cacheSize, equalityCheck), repure, repureOneCacheCreator(equalityCheck)

repureCreator(cacheSize, equalityCheck)

函数repureCreator 返回一个repure, 可以缓存cacheSize个结果。 在判断入参是否相同的时候使用 equalityCheck。 默认的 equalityCheck 是:

function defaultEqualityCheck(a, b) {
    return a === b
}

另外提供一个 shallowEqual: import { shallowEqual } from 'repure'

repure

大部分情况下,你应该使用这个方法。 这个和你使用reselct的createSelector的效果是一样的, 使用=== 比较相等, cacheSize是1。 repure接受一个pure function, 返回这个方法的 缓存版本

repureOneCacheCreator(equalityCheck)

repureCreator 在cacheSize=1 时的优化版本

另外提供一个 batchRepure(obj, repure) 方法。 用法如下:

import * as fobj from './xx' // file export 衍生函数

const fobj2 = batchRepure(obj, repure)