Git Product home page Git Product logo

Comments (5)

danny-andrews avatar danny-andrews commented on May 18, 2024 1

@TN1ck I don't understand how this code works. Won't appliedSelectors just be an array of the results of running the passed-passed in selectors? Something like: [2, 'cool val', {}]. So when you run _.merge(...appliedSelectors) you're going to get garbage out:

{ [Number: 2]
  '0': 'c',
  '1': 'o',
  '2': 'o',
  '3': 'l',
  '4': ' ',
  '5': 'v',
  '6': 'a',
  '7': 'l' }

from reselect.

panayi avatar panayi commented on May 18, 2024

Thanks @TN1ck. I think to be more consistent with (state, props) it should be

let appliedSelectors = selectors.map(fn => {
  return fn(_, this.props);
})

from reselect.

panayi avatar panayi commented on May 18, 2024

Also here is a version with ES6 classes:

import React, { Component } from 'react'
import _ from 'lodash'

const select = (...selectors) => {
  return WrappedComponent => class extends Component {
    render() {
      const appliedSelectors = selectors.map(fn => {
        return fn(_, this.props)
      })
      const calculatedProps = _.merge(...appliedSelectors)
      return (
        <WrappedComponent {...this.props} {...calculatedProps} />
      )
    }
  }
}

export default select

// Usage:
// select(avatarSelector)(AvatarComponent)

from reselect.

ellbee avatar ellbee commented on May 18, 2024

@TN1ck @panayi Great, I appreciate both of you writing this up! Thanks.

@panayi Looks like you are passing lodash as the 1st param into the function getting memoized? I guess that was intended to be a placeholder. I'm not sure that I agree about (_, props) being more consistent, my initial feeling is that I would leave that function call how @TN1ck had it.

This would be a good fit for this FAQ question on the readme if anyone fancies submitting a pull request. No worries if not, I'll get around to adding it soon.

from reselect.

mindjuice avatar mindjuice commented on May 18, 2024

@TN1ck Sorry, I'm not following what the purpose of this is. Do you have a more concrete example and an explanation of why you can't use reselect in the normal way?

Thanks.

from reselect.

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.