Redux 的选择器库 Reselect
- 授权协议: MIT
- 开发语言: JavaScript TypeScript
- 操作系统: 跨平台
- 软件首页: https://github.com/reduxjs/reselect
- 软件文档: https://github.com/reduxjs/reselect
- 官方下载: https://github.com/reduxjs/reselect
软件介绍
Reselect 是一个 Redux 的选择器库,灵感来源于 NuclearJS 。
Selector 可以计算衍生的数据,可以让 Redux 存储尽可能少的 state 。
Selector 非常高效,除非某个参数发生变化,否则不会发生计算过程。
Selector 是可组合的,它们可以输入、传递到其他的选择器。
示例:
import { createSelector } from 'reselect'
const shopItemsSelector = state => state.shop.items
const taxPercentSelector = state => state.shop.taxPercent
const subtotalSelector = createSelector(
shopItemsSelector,
items => items.reduce((acc, item) => acc + item.value, 0)
)
const taxSelector = createSelector(
subtotalSelector,
taxPercentSelector,
(subtotal, taxPercent) => subtotal * (taxPercent / 100)
)
export const totalSelector = createSelector(
subtotalSelector,
taxSelector,
(subtotal, tax) => ({ total: subtotal + tax })
)
let exampleState = {
shop: {
taxPercent: 8,
items: [
{ name: 'apple', value: 1.20 },
{ name: 'orange', value: 0.95 },
]
}
}
console.log(subtotalSelector(exampleState)) // 2.15
console.log(taxSelector(exampleState)) // 0.172
console.log(totalSelector(exampleState)) // { total: 2.322 }
编程人生(上卷)
[美] Peter Seibel / 图灵社区 / 人民邮电出版社 / 2014-12 / 39.00元
这是一本访谈笔录,记录了当今最具个人魅力的15 位软件先驱的编程生涯。包括Donald Knuth、Jamie Zawinski、Joshua Bloch、Ken Thompson等在内的业界传奇人物,为我们讲述了他们是怎么学习编程的,在编程过程中发现了什么以及他们对未来的看法,并对诸如应该如何设计软件等长久以来一直困扰很多程序员的问题谈了自己的观点。中文版分为上下卷,上卷介绍8位大师。一起来看看 《编程人生(上卷)》 这本书的介绍吧!
