
Security News
/Research
Wallet-Draining npm Package Impersonates Nodemailer to Hijack Crypto Transactions
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
@taskworld.com/rereselect
Advanced tools
A library that generates memoized selectors and supports dynamic dependency tracking.
Not to be confused with Re-reselect which is an enhancement to Reselect. This is an entirely separate project.
A library that generates memoized selectors like Reselect but:
Design constraints:
Notes:
The Reselect “shopping cart” example:
import { makeSelector } from '@taskworld.com/rereselect'
// “Simple” selectors are the same.
const shopItemsSelector = state => state.shop.items
const taxPercentSelector = state => state.shop.taxPercent
// Instead of `createSelector`, it is called `makeSelector`.
//
// Instead of declaring dependencies upfront, use the `query` function
// to invoke other selectors. In doing so, the dependency will
// automatically be tracked.
//
const subtotalSelector = makeSelector(query =>
query(shopItemsSelector).reduce((acc, item) => acc + item.value, 0)
)
const taxSelector = makeSelector(
query => query(subtotalSelector) * (query(taxPercentSelector) / 100)
)
const totalSelector = makeSelector(query => ({
total: query(subtotalSelector) + query(taxSelector)
}))
Dynamic dependency tracking:
let state = {
fruits: {
a: { name: 'Apple' },
b: { name: 'Banana' },
c: { name: 'Cantaloupe' }
},
selectedFruitIds: ['a', 'c']
}
// I want to query the selected fruits...
const selectSelectedFruits = makeSelector(query =>
query(state => state.selectedFruitIds).map(id =>
query(state => state.fruits[id])
)
)
// Use like any other selectors:
console.log(selectSelectedFruits(state)) // [ { name: 'Apple' }, { name: 'Cantaloupe' } ]
// Since data selection is fine-grained, changes to unrelated parts
// of the state will not cause a recomputation.
state = {
...state,
fruits: {
...state.fruits,
b: { name: 'Blueberry' }
}
}
console.log(selectSelectedFruits(state)) // [ { name: 'Apple' }, { name: 'Cantaloupe' } ]
console.log(selectSelectedFruits.recomputations()) // 1
This library is only concerned with creating a selector system that supports dynamic dependency tracking. So, it is up to you to implement parameterized selectors support.
This is how we do it (we also added displayName
property to our selectors to
make them easier to debug):
export function makeParameterizedSelector(
displayName,
selectionLogicGenerator
) {
const memoized = new Map()
return Object.assign(
function selectorFactory(...args) {
const key = args.join(',')
if (memoized.has(key)) return memoized.get(key)!
const name = `${displayName}(${key})`
const selectionLogic = selectionLogicGenerator(...args)
const selector = makeSelector(selectionLogic)
selector.displayName = name
memoized.set(key, selector)
return selector
},
{ displayName }
)
}
FAQs
A library that generates memoized selectors and supports dynamic dependency tracking.
We found that @taskworld.com/rereselect demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.