-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is double-connecting a component bad/inefficient? #403
Comments
Uh... semi-stupid question: why are you needing to use |
@markerikson Well basically, because what action gets returned to the component needs to use state. I don't have access to dispatch in In this case, the state is the current user's authorization. The result is either the real action, or nothing. Our app has role based authentication (details stored in state.auth) where employees in the admin role can can perform write actions from a screen where other users can only get a readonly version. The components key off whether the event handler functions are null or not to make that determination. |
I'm think maybe code that uses react+redux+reselect could use a simpler implementation of |
Hmm. A couple thoughts:
|
The double connect is the alternative to using Having the component call the method with the parameters prebound avoids extra method create in the component, ex: |
I'm working on an alternate version of |
Hmm. What's the actual meaningful difference with that approach? |
@jimbolla Your use of dispatch in this way does feel a bit awkward to me but I can see why having dispatch available in the selector can be useful if you want to keep all this kind of thing in selectors exclusively.
const provideDispatch = connect();
export default compose(
provideDispatch, // + props.dispatch
connect(createSelector(
selectApp,
selectOnToggleIsActive,
(app, onToggleIsActive) => ({
appId: app.id,
onToggleIsActive,
})
)),
)(EditMenu); this way you can swap out the implementation for |
@gnoff That's a good idea. If I don't end up using my own implementation of @markerikson Partly stylistic and syntactical preference, partly being able to leverage the abilities of import connectToStore, { selectProps, partialApply } from 'appcenter/utils/connectToStore';
import { toggleIsActive } from '../actions/apps';
import { getApp, getAppId, getIsAppsAdmin } from '../selectors/apps';
// later...
export default connectToStore(
({ toggleIsActive }),
({ toggleIsActive }) => { // eslint-disable-line no-shadow
const getToggleIsActive = partialApply(toggleIsActive, getAppId);
return selectProps(
[getApp, getToggleIsActive, getIsAppsAdmin],
(app, onToggleIsActive, isAppsAdmin) => ({
appId: app.id,
canCustomize: Boolean(app.customAppConfig),
isActive: app.isActive,
onToggleIsActive: isAppsAdmin ? onToggleIsActive : null,
})
);
}
)(EditMenu); Now I have both state and bound action creators available so I can build my props object in a single pass. |
Update updeep's url
I've found the syntax to be less awkward, especially when using
reselect
, to connect once to get access todispatch
, then connect a second time to do state stuff and memoize, vs. having to define amergeProps
function. I'm just concerned that double-connecting is going to somehow cause me problems, or that I'm losing some crucial optimization thatconnect()
would be doing if I were doing it with a singleconnect
.For example, I have this:
The text was updated successfully, but these errors were encountered: