-
Notifications
You must be signed in to change notification settings - Fork 427
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compat component to maintain compatibility across react version (#387)
* Moving logic to compat component * Made compat component abstract * path revert * sticky changes * Added will update * Comments added * Fixed unnecessary rerender
- Loading branch information
1 parent
f55b989
commit 1933182
Showing
10 changed files
with
106 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import * as React from "react"; | ||
|
||
//Interim solve given we want to be active on old react as well for now. | ||
export abstract class ComponentCompat<T1 = {}, T2 = {}, SS = any> extends React.Component<T1, T2, SS> { | ||
private _hasRenderedOnce: boolean = false; | ||
private _didPropsChange: boolean = false; | ||
|
||
constructor(props: T1, context?: any) { | ||
super(props, context); | ||
} | ||
|
||
public shouldComponentUpdate(newProps: T1, newState: T2): boolean { | ||
if (this.props !== newProps) { | ||
this.componentWillReceivePropsCompat(newProps); | ||
} | ||
return true; | ||
} | ||
|
||
//setState inside will not update the existing cycle, not a true replacement for componentWillReceiveProps | ||
public componentWillReceivePropsCompat(newProps: T1): void { | ||
//no op | ||
} | ||
|
||
public componentWillMountCompat(): void { | ||
//no op | ||
} | ||
|
||
public componentWillUpdateCompat(): void { | ||
//no op | ||
} | ||
|
||
public render(): React.ReactNode { | ||
if (!this._hasRenderedOnce) { | ||
this._hasRenderedOnce = true; | ||
this.componentWillMountCompat(); | ||
} else { | ||
this.componentWillUpdateCompat(); | ||
} | ||
return this.renderCompat(); | ||
} | ||
|
||
public abstract renderCompat(): React.ReactNode; | ||
} |