Coder Social home page Coder Social logo

Comments (4)

skortchmark9 avatar skortchmark9 commented on May 24, 2024

Hey @bdurrer - I don't use re-reselect in my own apps, so I never thought about this use case. However, if you can come up with a way to get it to work I'd be happy to take a PR

from reselect-tools.

parkerault avatar parkerault commented on May 24, 2024

Is this just an issue with re-reselect support, or is it an issue with any multi-arity selector? In src/index.js#checkSelector every selector is executed with the result of stateGetter, and off the top of my head I can't think of any easy way to provide a default ...rest parameter for each selector. I always use a second props object parameter, which I think is a pretty common pattern (any other parameter type can't be composed), so you could possibly have an optional second parameter for registerSelectors with a default props object. However, you would need to provide it with a key and value for every selector in the tree, which would be enormous for any non-trivial application. You could alternatively require an additional defaultProps value for each multi-parameter function, but this just splits up the same amount of work. I don't see any reasonable way to implement this feature that wouldn't require an extensive integration effort.

So in summary:

  • A defaultProps parameter to registerSelectors would require a key-value pair for every unique key used in the application. This would also result in the same key-value pair being used for every selector that consumes that key, which may not work.
  • Adding a defaultProps value or a default parameter value for each "props" selector (i.e. (__, props = { prop: 1 }) => props.prop) to every multi-arity selector would allow you to specify the default props individually, but would require even more work than the single defaultProps parameter to registerSelectors

from reselect-tools.

skortchmark9 avatar skortchmark9 commented on May 24, 2024

Thanks for the info! You're correct that it's probably more a consequence of the second argument - I've never had to use that myself since I tend to think of selectors more as a mechanism for holding whole-app computed state.

from reselect-tools.

bdurrer avatar bdurrer commented on May 24, 2024

Maybe displaying all cached re-reselectors is not practicable anyway. I guess it could also have a negative impact on performance.
At least in our setup, there are only a handful of possible cach entries (each app tab has it's own selector cache entry) and it would already be nice to view one or two variants of each re-reselectors.

How about having a second parameter on registerSelectors, which allows to provides a function for each selector. It's job would be to calculate the arguments for one selector, similar to what getStateWith does for the state.

The function would simply return the required input for one of the cached re-reselectors. One could easily make that function dynamically switch caches based on some extern data, e.g. a global cache-key variable, so you can browse through the selectors based on an external controller.

e.g. something like


function selectorArgs(state, selectorName) {
  if (reasons) {
    return ['param1', 'param2']
  } else {
    return ['param3', 'param4']
  }
}

registerSelectors({ mySelector }, { mySelector: selectorArgs })

would then call the selector like this

const state = _getState()
const selectorArgs = _allSelectorsArgs[selectorName]
const args = selectorArgs ? selectorArgs(state, selectorName) : []
extra.output = selector(state , ...args)

from reselect-tools.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.