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
87.8
Supply Chain
99.5
Quality
82.1
Maintenance
100
Vulnerability
100
License
Updated on 11 Mar 2024
Minified
Minified + Gzipped
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
16.5%
Compared to previous day
Last week
-6.5%
Compared to previous week
Last month
7.6%
Compared to previous month
Last year
-27.6%
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
license file not detected
Details
Reason
project is not fuzzed
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 2024-11-25
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