Skip to content

Potential Refactor #227

Description

@brianreavis

First, react-select is slick! It's been awesome to work with. I've been wanting to make some bugfixes, but have ended up with my hands tied because of a few things that are hard to reason about. This list also contains some other notes:

  • Drop the "dist" files altogether. React's already basically impossible to use without a bundler, so I'm not sure if it's doing much good? "Please don't update the dist files" gets really old to say to the million people who don't read the contributing notes.
  • Build "lib" when publishing, but ignore in repo (same point as above)
  • Reduce/reconsider usage of componentWillMount? It's triggered on the server, so calling autoloadAsyncOptions and such here seems strange. Also, I'm not sure this._bindCloseMenuIfClickedOutside = ... etc are assigned in this way here?
  • Enforce "options" prop to be immutable. Whenever a prop changes, there's two JSON.stringify calls in componentWillReceiveProps that are expensive for large datasets. It'd be more efficient if there could just be a strict equality check here.
  • Move functionality not directly related to the control out to separate files/modules. The includes:
    • DOM event binding
    • Option searching (for selectize I split this out to sifter.js because it ballooned and needlessly complicated the library)
  • Consolidate menu opening code to happen in one spot. As it is right now, the menu's events are bound multiple places throughout the library. I think the intent is to consolidate setState calls? React will batch these so I think's a bit moot and leading to more problems than it's solving? It's tough to track down where events are bound/unbound.
  • Don't modify state directly (esp in render methods). e.g. L630-L634
  • Use ...spread in cases like these.
  • Why does the this context matter on callbacks? E.g. callback.call(this, {}); All React element methods are auto-bound already.
  • Consider Allow any type in value #25. Given that React's point is abstracting away DOM craziness, I think that the "values must be strings" is quite limiting... it leads to lots of application-level casting in onChange events. It feels very weird to cast an ID to a string for <Select> then cast it back to a number.

@JedWatson @dcousens What are your thoughts on these? I almost started on a lot of these today, but it'll create a lot of merge conflicts on existing PRs and be a little risky w/o tests.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions