Gathering detailed insights and metrics for reselect-tree
Gathering detailed insights and metrics for reselect-tree
Gathering detailed insights and metrics for reselect-tree
Gathering detailed insights and metrics for reselect-tree
Abstraction around reactjs's `reselect`to define trees of selectors
npm install reselect-tree
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
3,919,742
Last Day
1,999
Last Week
10,683
Last Month
44,560
Last Year
561,876
5 Stars
65 Commits
3 Forks
13 Watchers
3 Branches
9 Contributors
Updated on Mar 11, 2024
Minified
Minified + Gzipped
Latest Version
1.3.7
Package Id
reselect-tree@1.3.7
Unpacked Size
27.14 kB
Size
9.13 kB
File Count
3
NPM Version
6.14.16
Node Version
12.22.10
Cumulative downloads
Total Downloads
Last Day
45.7%
1,999
Compared to previous day
Last Week
16.8%
10,683
Compared to previous week
Last Month
-14.6%
44,560
Compared to previous month
Last Year
-20.9%
561,876
Compared to previous year
Wrapper around reactjs's reselect library for creating trees of selectors.
Designed to allow selectors to be organized into separate namespaces easily, with the ability to identify dependencies between selectors in the tree.
Install with:
npm install --save reselect-tree
Then define a file selectors.js
:
1import { createSelectorTree, createLeaf } from "reselect-tree"; 2 3const selectors = require("./dist/reselect-tree.js"); 4const createSelectorTree = selectors.createSelectorTree; 5const createLeaf = selectors.createLeaf; 6 7const select = createSelectorTree({ 8 shop: { 9 taxPercent: state => state.shop.taxPercent 10 }, 11 cart: { 12 items: state => state.cart.items, 13 14 subtotal: createLeaf( 15 ['./items'], 16 17 (items) => items.reduce((acc, item) => acc + item.value, 0) 18 ), 19 20 tax: createLeaf( 21 ['/shop/taxPercent', './subtotal'], 22 23 (taxPercent, subtotal) => subtotal * (taxPercent / 100) 24 ), 25 26 total: createLeaf( 27 ['./subtotal', './tax'], (subtotal, tax) => ({ total: subtotal + tax }) 28 ) 29 } 30}); 31 32 33let exampleState = { 34 shop: { 35 taxPercent: 8, 36 }, 37 cart: { 38 items: [ 39 { name: 'apple', value: 1.20 }, 40 { name: 'orange', value: 0.95 }, 41 ] 42 } 43} 44 45console.log(select.cart.subtotal(exampleState)) // 2.15 46console.log(select.cart.tax(exampleState)) // 0.172 47console.log(select.cart.total(exampleState)) // { total: 2.322 }
You can also select non-leaf nodes, for structured representations:
1console.log(select.cart(exampleState)) 2{ items: 3 [ { name: 'apple', value: 1.2 }, 4 { name: 'orange', value: 0.95 } ], 5 subtotal: 2.15, 6 tax: 0.172, 7 total: { total: 2.322 } }
You can override the default aggregation behavior by defining a custom child
_
. e.g.:
1const select = createSelectorTree({ 2 shop: { 3 taxPercent: state => state.shop.taxPercent 4 }, 5 cart: { 6 _: createLeaf( 7 ['./items', './total'], 8 9 (items, total) => ({ items, total }) 10 ), 11 12 items: state => state.cart.items, 13 14 subtotal: createLeaf( 15 ['./items'], 16 17 (items) => items.reduce((acc, item) => acc + item.value, 0) 18 ), 19 20 tax: createLeaf( 21 ['/shop/taxPercent', './subtotal'], 22 23 (taxPercent, subtotal) => subtotal * (taxPercent / 100) 24 ), 25 26 total: createLeaf( 27 ['./subtotal', './tax'], (subtotal, tax) => ({ total: subtotal + tax }) 28 ) 29 } 30});
This changes how select.cart
behaves, instead acting as select.cart._
:
1console.log(select.cart(exampleState)); // { items: 2 // [ { name: 'apple', value: 1.2 }, 3 // { name: 'orange', value: 0.95 } ], 4 // total: { total: 2.322 } } 5console.log(select.cart._(exampleState)); // { items: 6 // [ { name: 'apple', value: 1.2 }, 7 // { name: 'orange', value: 0.95 } ], 8 // total: { total: 2.322 } }
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
Found 7/18 approved changesets -- score normalized to 3
Reason
project is archived
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
license file not detected
Details
Reason
security policy file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-04-28
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More