11import * as React from 'react' ;
2- import createReactClass from 'create-react-class' ;
3- import Reflux from 'reflux' ;
42
53import { loadSdkUpdates } from 'app/actionCreators/sdkUpdates' ;
64import { Client } from 'app/api' ;
@@ -29,21 +27,17 @@ type Props = {
2927} ;
3028
3129type State = {
32- sdkUpdates : ProjectSdkUpdates [ ] ;
30+ sdkUpdates : ProjectSdkUpdates [ ] | null ;
3331} ;
3432
3533function withSdkUpdates < P extends InjectedProps > (
3634 WrappedComponent : React . ComponentType < P >
3735) {
38- const ProjectSdkSuggestions = createReactClass <
39- Props & Omit < P , keyof InjectedProps > ,
36+ class WithProjectSdkSuggestions extends React . Component <
37+ Omit < P , keyof InjectedProps > & Props ,
4038 State
41- > ( {
42- mixins : [ Reflux . listenTo ( SdkUpdatesStore , 'onSdkUpdatesUpdate' ) as any ] ,
43-
44- getInitialState ( ) {
45- return { sdkUpdates : [ ] } ;
46- } ,
39+ > {
40+ state : State = { sdkUpdates : [ ] } ;
4741
4842 componentDidMount ( ) {
4943 const orgSlug = this . props . organization . slug ;
@@ -56,21 +50,32 @@ function withSdkUpdates<P extends InjectedProps>(
5650 }
5751
5852 loadSdkUpdates ( this . props . api , orgSlug ) ;
59- } ,
53+ }
54+
55+ componentWillUnmount ( ) {
56+ this . unsubscribe ( ) ;
57+ }
58+ unsubscribe = SdkUpdatesStore . listen ( ( ) => this . onSdkUpdatesUpdate ( ) , undefined ) ;
6059
6160 onSdkUpdatesUpdate ( ) {
6261 const sdkUpdates = SdkUpdatesStore . getUpdates ( this . props . organization . slug ) ?? null ;
6362 this . setState ( { sdkUpdates} ) ;
64- } ,
63+ }
6564
6665 render ( ) {
66+ // TODO(ts) This unknown cast isn't great but Typescript complains about arbitrary
67+ // types being possible. I think this is related to the additional HoC wrappers causing type data to
68+ // be lost.
6769 return (
68- < WrappedComponent { ...( this . props as P ) } sdkUpdates = { this . state . sdkUpdates } />
70+ < WrappedComponent
71+ { ...( ( this . props as unknown ) as P ) }
72+ sdkUpdates = { this . state . sdkUpdates }
73+ />
6974 ) ;
70- } ,
71- } ) ;
75+ }
76+ }
7277
73- return withOrganization ( withApi ( ProjectSdkSuggestions ) ) ;
78+ return withOrganization ( withApi ( WithProjectSdkSuggestions ) ) ;
7479}
7580
7681export default withSdkUpdates ;
0 commit comments