react-copy-write icon indicating copy to clipboard operation
react-copy-write copied to clipboard

createSelector support multiple selectors

Open gingur opened this issue 7 years ago • 3 comments

Feature Request

Similar to reselect, would be nice to compose selectors with other selectors, that way the business logic can be abstracted and isolated to the selector.

Example

// basic example: state.user.avatar.src
const user = createSelector(state => state.user);
const userAvatar = createSelector(user, userState => userState.avatar);
const userAvatarSrc = createSelector(userAvatar, userAvatarState => userAvatarState.src);

// advanced example: state.user.avatar.src || state.config.defaultAvatar
const config = createSelector(state => state.config);
const defaultAvatarSrc = createSelector(config, configState => configState.defaultAvatar);
const avatar = createSelector(
  userAvatarSrc,
  defaultAvatarSrc,
  (userAvatarSrcState, defaultAvatarSrcState) => (
    userAvatarSrcState || defaultAvatarSrcState
  )
);

gingur avatar Sep 28 '18 17:09 gingur

It seems like createSelector is just an identity function at this point, is there consideration to just use reselect to handle memoizing?

seethroughdev avatar Dec 19 '18 23:12 seethroughdev

@seethroughtrees the idea was that createSelector would use the unstable_observedBits context API, but it's not clear if that API will ever become stable. I believe reselect already works pretty well with RCW but I'd be open to making that integration better.

aweary avatar Dec 21 '18 03:12 aweary

Makes perfect sense. Thanks for the great library @aweary .

seethroughdev avatar Dec 21 '18 17:12 seethroughdev