我想知道是否有一种方法可以避免需要检测我的Redux-Aware组件。这似乎需要过度的脚手架。Redux + React + Typescript:我如何减少所需的脚手架数量?
例如,以下是声明一个终极版知晓组件所需的最低代码:
class _MyActualComponent extends React.Component<reduxScafolding.Action & { myReduxState: reduxScafolding.ReduxState; pushPath: ReduxSimpleRouter.pushPath; } & { myActualProp: string; }, {}>{
//my component's implementation goes here.
}
/** type for casting (so consumers know the props they are required to pass */
class IMyComponentVisibleType extends React.Component<{ myActualProp: string; }, {}> { };
/** instrument my component with redux */
export var MyComponent = ReactRedux.connect(
(reduxStoreState) => { //subscripbe to reduxStore updates (Called every change).
return { myReduxState: reduxStoreState.myReduxState }; //map myReduxState to props
}
, _.merge({}, {}, { pushPath: ReduxSimpleRouter.pushPath }, reduxScafolding.action) as any //redux-binds, then includes the pushPath() method for use in our _App Component
)(_MyActualComponent) as any as typeof IMyComponentVisibleType;