Apply strictNullChecks
around the codebase (#10302
* Apply `strictNullChecks` around the codebase * Iterate PR
This commit is contained in:
parent
7c2bb966d0
commit
4b8bada24b
26 changed files with 112 additions and 77 deletions
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import React, { ReactInstance } from "react";
|
||||
import React, { Key, ReactElement, ReactInstance } from "react";
|
||||
import ReactDom from "react-dom";
|
||||
|
||||
interface IChildProps {
|
||||
|
@ -42,7 +42,7 @@ interface IProps {
|
|||
*/
|
||||
export default class NodeAnimator extends React.Component<IProps> {
|
||||
private nodes: Record<string, ReactInstance> = {};
|
||||
private children: { [key: string]: React.DetailedReactHTMLElement<any, HTMLElement> };
|
||||
private children: { [key: string]: ReactElement };
|
||||
public static defaultProps: Partial<IProps> = {
|
||||
startStyles: [],
|
||||
};
|
||||
|
@ -72,17 +72,17 @@ export default class NodeAnimator extends React.Component<IProps> {
|
|||
private updateChildren(newChildren: React.ReactNode): void {
|
||||
const oldChildren = this.children || {};
|
||||
this.children = {};
|
||||
React.Children.toArray(newChildren).forEach((c: any) => {
|
||||
if (oldChildren[c.key]) {
|
||||
const old = oldChildren[c.key];
|
||||
const oldNode = ReactDom.findDOMNode(this.nodes[old.key]);
|
||||
React.Children.toArray(newChildren).forEach((c: ReactElement) => {
|
||||
if (oldChildren[c.key!]) {
|
||||
const old = oldChildren[c.key!];
|
||||
const oldNode = ReactDom.findDOMNode(this.nodes[old.key!]);
|
||||
|
||||
if (oldNode && (oldNode as HTMLElement).style.left !== c.props.style.left) {
|
||||
this.applyStyles(oldNode as HTMLElement, { left: c.props.style.left });
|
||||
}
|
||||
// clone the old element with the props (and children) of the new element
|
||||
// so prop updates are still received by the children.
|
||||
this.children[c.key] = React.cloneElement(old, c.props, c.props.children);
|
||||
this.children[c.key!] = React.cloneElement(old, c.props, c.props.children);
|
||||
} else {
|
||||
// new element. If we have a startStyle, use that as the style and go through
|
||||
// the enter animations
|
||||
|
@ -95,14 +95,14 @@ export default class NodeAnimator extends React.Component<IProps> {
|
|||
newProps.style = startStyle;
|
||||
}
|
||||
|
||||
newProps.ref = (n) => this.collectNode(c.key, n, restingStyle);
|
||||
newProps.ref = (n) => this.collectNode(c.key!, n, restingStyle);
|
||||
|
||||
this.children[c.key] = React.cloneElement(c, newProps);
|
||||
this.children[c.key!] = React.cloneElement(c, newProps);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private collectNode(k: string, node: React.ReactInstance, restingStyle: React.CSSProperties): void {
|
||||
private collectNode(k: Key, node: React.ReactInstance, restingStyle: React.CSSProperties): void {
|
||||
if (node && this.nodes[k] === undefined && this.props.startStyles.length > 0) {
|
||||
const startStyles = this.props.startStyles;
|
||||
const domNode = ReactDom.findDOMNode(node);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue