Installations
npm install reselect-tools
Developer Guide
Typescript
❌ No
Module System
CommonJS
Node Version
5.4.1
NPM Version
3.3.12
Score
85.6
Supply Chain
99.1
Quality
75.3
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Developer
skortchmark9
Statistics
Updated on 18 Sept 2024
Bundle Size
4.01 kB
Minified
1.60 kB
Minified + Gzipped
Languages
JavaScript (92.14%)
CSS (6.96%)
HTML (0.9%)
Total Downloads
Cumulative downloads
Total Downloads
2,003,9562,003,956
Last day
-3.1%
Compared to previous day
Last week
-22.3%
Compared to previous week
Last month
6%
Compared to previous month
Last year
10.9%
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Reselect Tools
Tools for working with the reselect library: Check selector dependencies, inputs, outputs, and recomputations at any time without refreshing!
1export const data$ = (state) => state.data; 2export const ui$ = (state) => state.ui; 3export const users$ = createSelector(data$, (data) => data.users); 4export const currentUser$ = createSelector(ui$, users$, (ui, users) => users[ui.currentUser]); 5... 6 7// in configureStore.js 8import * as selectors from './selectors.js' 9import * as ReselectTools from 'reselect-tools' 10 11ReselectTools.getStateWith(() => store.getState()) // allows you to get selector inputs and outputs 12ReselectTools.registerSelectors(selectors) // register string names for selectors 13... 14ReselectTools.checkSelector('currentUser$') 15=> { 16 inputs: [{currentUser: 1}, users: {1: {name: 'sam'}}] 17 outputs: {name: 'sam'}, 18 dependencies: [ui$, users$], 19 recomputations: 1, 20 isNamed: false, 21 selectorName: 'currentUser$' 22} 23selectorGraph() 24=> { 25 nodes: { 26 "data$": { 27 name: "data$", 28 recomputations: "N/A" 29 }, 30 "ui$": { 31 name: "ui$", 32 recomputations: "N/A" 33 }, 34 "users$": { 35 name: "user$", 36 recomputations: 1 37 }, 38 "currentUser$": { 39 name: "currentUser$", 40 recomputations: 1 41 }, 42 }, 43 edges: [ 44 { from: users$, to: data$ }, 45 { from: users$, to: data$ }, 46 { from: currentUser$, to: users$ }, 47 { from: currentUser$, to: ui$ }, 48 ] 49}
Table of Contents
Motivation
It's handy to visualize the application state tree with the Redux Devtools. But I was using selectors a lot, and there was no easy way to visualize the computed state tree. So, I created this library to output graphs like this one:
This library was intended to be used with the chrome extension. However, it can be still be useful without the chrome extension installed. The chrome extension will be useless without this library.
See the original reselect issue here.
Getting Started
Firstly, I apologize in advance that this section is required. It would be great to match the experience of installing redux devtools or react's. Hopefully the tools will be more tightly integrated with reselect at some point and these steps won't be necessary.
-
Install the Package
npm install -s reselect-tools
-
Grab the Chrome Extension
-
Building the Graph:
In order to start building out the selector graph, we need to tell the devtools about the selectors.
import { registerSelectors } from 'reselect-tools' registerSelectors({ mySelector$ })
If you're keeping all your selectors in the same place, this is dead simple:
import * as selectors from './selectors.js' registerSelectors(selectors)
That's it! At this point you should be able to open the devtools and view the selector graph.
The tools will automatically discover and name dependencies of the selectors. If you want to override the name of a selector, you can do so:
const foo$ = createSelector(bar$, (foo) => foo + 1); foo$.selectorName = 'bar$' // selector will show up as 'bar'
-
Checking Selector Inputs and Outputs
Imagine that your tests are passing, but you think some selector in your app might be receiving bad input from a depended-upon selector. Where in the chain is the problem? In order to allow
checkSelector
and by extension, the extension, to get this information, we need to give Reselect Tools some way of feeding state to a selector.import store from './configureStore' ReselectTools.getStateWith(() => store.getState())
Example
The example is running here. Grab the extension and take a look!
npm run example
API
getStateWith(func)
getStateWith
accepts a function which returns the current state. This state is then passed into checkSelector
. In most cases, this will be store.getState()
checkSelector(selector)
Outputs information about the selector at the given time.
By default, outputs only the recomputations of the selector.
If you use getStateWith
, it will output the selector's input and output values.
If you use registerSelectors
, you can pass it the string name of a selector.
1const two$ = () => 2; 2const four$ = () => 4 3const mySelector$ = createSelector(two$, four$, (two, four) => two + four) 4registerSelectors({ mySelector$ }) 5getStateWith(() => null) 6 7checkSelector('mySelector$') // { 8 inputs: [2, 4], 9 output: 6, 10 dependencies: [two$, four$], 11 recomputations: 1, 12 }
selectorGraph(selectorKey = defaultSelectorKey)
selectorGraph
outputs a POJO with nodes and edges. A node is a selector in the tree, and an edge goes from a selector to the selectors it depends on.
1selectorGraph() 2// { 3// nodes: { 4// "data$": { 5// name: "data$", 6// recomputations: "N/A" 7// }, 8// "ui$": { 9// name: "ui$", 10// recomputations: "N/A" 11// }, 12// "users$": { 13// name: "user$", 14// recomputations: 1 15// }, 16// "currentUser$": { 17// name: "currentUser$", 18// recomputations: 1 19// }, 20// }, 21// edges: [ 22// { from: users$, to: data$ }, 23// { from: users$, to: data$ }, 24// { from: currentUser$, to: users$ }, 25// { from: currentUser$, to: ui$ }, 26// ] 27// }
Using custom selectorKeys
Nodes in the graph are keyed by string names. The name is determined by the selectorKey
function. This function takes a selector and outputs a string which must be unique and consistent for a given selector. The defaultSelectorKey
looks for a function name, then a match in the registry, and finally resorts to calling toString
on the selector's resultFunc
.
See the tests for an alternate selectorKey.
registerSelectors(keySelectorObj)
Add a named selector to the graph. Set selector names as keys and selectors as values.
Without The Extension
If you're using an unsupported browser, or aren't happy with the extension, you can still get at the data.
The dev tools bind to your app via this global:
window.__RESELECT_TOOLS__ = {
selectorGraph,
checkSelector
}
Even without the devtools, you can call __RESELECT_TOOLS__.checkSelector('mySelector$')
from the developer console or __RESLECT_TOOLS__.selectorGraph()
to see what's going on. If the JSON output of the graph is hard to parse, there's an example of how to create a visual selector graph here.
License
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 2/11 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 27 are checked with a SAST tool
Reason
88 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-3v6h-hqm4-2rg6
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-whgm-jr23-g3j9
- Warn: Project is vulnerable to: GHSA-fwr7-v2mv-hh25
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-pp7h-53gx-mx7r
- Warn: Project is vulnerable to: GHSA-cwfw-4gq5-mrqx
- Warn: Project is vulnerable to: GHSA-g95f-p29q-9xw4
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-hm92-vgmw-qfmx
- Warn: Project is vulnerable to: GHSA-wxhq-pm8v-cw75
- Warn: Project is vulnerable to: GHSA-257v-vj4p-3w2h
- Warn: Project is vulnerable to: GHSA-4vmm-mhcq-4x9j
- Warn: Project is vulnerable to: GHSA-pxg6-pf52-xh8x
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-9vvw-cc9w-f27h
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-hr2v-3952-633q
- Warn: Project is vulnerable to: GHSA-h6ch-v84p-w6p9
- Warn: Project is vulnerable to: GHSA-4gmj-3p3h-gm8h
- Warn: Project is vulnerable to: GHSA-rv95-896h-c2vc
- Warn: Project is vulnerable to: GHSA-qw6h-vgh9-j6wx
- Warn: Project is vulnerable to: GHSA-qrmc-fj45-qfc2
- Warn: Project is vulnerable to: GHSA-mpcf-4gmh-23w8
- Warn: Project is vulnerable to: GHSA-9qj9-36jm-prpv
- Warn: Project is vulnerable to: GHSA-8r6j-v8pm-fqw3
- Warn: Project is vulnerable to: MAL-2023-462
- Warn: Project is vulnerable to: GHSA-xf7w-r453-m56c
- Warn: Project is vulnerable to: GHSA-qh2h-chj9-jffq
- Warn: Project is vulnerable to: GHSA-44pw-h2cw-w3vq
- Warn: Project is vulnerable to: GHSA-jp4x-w63m-7wgm
- Warn: Project is vulnerable to: GHSA-c429-5p7v-vgjp
- Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37
- Warn: Project is vulnerable to: GHSA-4hpf-3wq7-5rpr
- Warn: Project is vulnerable to: GHSA-f522-ffg8-j8r6
- Warn: Project is vulnerable to: GHSA-7r28-3m3f-r2pr
- Warn: Project is vulnerable to: GHSA-r8j5-h5cx-65gg
- Warn: Project is vulnerable to: GHSA-2pr6-76vf-7546
- Warn: Project is vulnerable to: GHSA-8j8c-7jfh-h6hx
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-282f-qqgm-c34q
- Warn: Project is vulnerable to: GHSA-76p3-8jx3-jpfq
- Warn: Project is vulnerable to: GHSA-3rfm-jhwj-7488
- Warn: Project is vulnerable to: GHSA-hhq3-ff78-jv3g
- Warn: Project is vulnerable to: GHSA-jf85-cpcp-j695
- Warn: Project is vulnerable to: GHSA-fvqr-27wr-82fm
- Warn: Project is vulnerable to: GHSA-4xc9-xhrj-v574
- Warn: Project is vulnerable to: GHSA-x5rq-j2xg-h7qm
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw
- Warn: Project is vulnerable to: GHSA-pp57-mqmh-44h7
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-wrvr-8mpx-r7pp
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m / GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-w9mr-4mfr-499f
- Warn: Project is vulnerable to: GHSA-r683-j2x4-v87g
- Warn: Project is vulnerable to: GHSA-6394-6h9h-cfjg
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j
- Warn: Project is vulnerable to: GHSA-566m-qj78-rww5
- Warn: Project is vulnerable to: GHSA-7fh5-64p2-3v2j
- Warn: Project is vulnerable to: GHSA-p493-635q-r6gr
- Warn: Project is vulnerable to: GHSA-3965-hpx2-q597
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-6g33-f262-xjp4
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-m6fv-jmcg-4jfg
- Warn: Project is vulnerable to: GHSA-cm22-4g7w-348p
- Warn: Project is vulnerable to: GHSA-4rq4-32rv-6wp6
- Warn: Project is vulnerable to: GHSA-64g7-mvw6-v9qj
- Warn: Project is vulnerable to: GHSA-2m39-62fm-q8r3
- Warn: Project is vulnerable to: GHSA-mf6x-7mm4-x2g7
- Warn: Project is vulnerable to: GHSA-j44m-qm6p-hp7m
- Warn: Project is vulnerable to: GHSA-3jfq-g458-7qm9
- Warn: Project is vulnerable to: GHSA-5955-9wpr-37jh
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
- Warn: Project is vulnerable to: GHSA-g7q5-pjjr-gqvp
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-662x-fhqg-9p8v
- Warn: Project is vulnerable to: GHSA-394c-5j6w-4xmx
- Warn: Project is vulnerable to: GHSA-fhg7-m89q-25r3
- Warn: Project is vulnerable to: GHSA-wr3j-pwj9-hqq6
- Warn: Project is vulnerable to: GHSA-5v72-xg48-5rpm
- Warn: Project is vulnerable to: GHSA-776f-qx25-q3cc
Score
1.9
/10
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