TeactN: Fix detaching, remove unused code

This commit is contained in:
Alexander Zinchuk 2023-01-06 01:15:47 +01:00
parent 384e216e5f
commit d64b6f2854

View File

@ -54,7 +54,6 @@ const containers = new Map<string, {
ownProps: Props; ownProps: Props;
mappedProps?: Props; mappedProps?: Props;
forceUpdate: Function; forceUpdate: Function;
areMappedPropsChanged: boolean;
isDetached: boolean; isDetached: boolean;
detachReason: any; detachReason: any;
detachWhenChanged: DetachWhenChanged; detachWhenChanged: DetachWhenChanged;
@ -188,7 +187,6 @@ function updateContainers() {
} }
container.mappedProps = newMappedProps; container.mappedProps = newMappedProps;
container.areMappedPropsChanged = true;
container.DEBUG_updates++; container.DEBUG_updates++;
forceUpdate(); forceUpdate();
@ -248,7 +246,6 @@ export function withGlobal<OwnProps extends AnyLiteral>(
container = { container = {
mapStateToProps, mapStateToProps,
ownProps: props, ownProps: props,
areMappedPropsChanged: false,
forceUpdate, forceUpdate,
isDetached: false, isDetached: false,
detachReason: undefined, detachReason: undefined,
@ -269,19 +266,17 @@ export function withGlobal<OwnProps extends AnyLiteral>(
containers.set(id, container); containers.set(id, container);
} }
if (container.areMappedPropsChanged) {
container.areMappedPropsChanged = false;
}
if (!container.mappedProps || !arePropsShallowEqual(container.ownProps, props)) { if (!container.mappedProps || !arePropsShallowEqual(container.ownProps, props)) {
container.ownProps = props; container.ownProps = props;
if (!container.isDetached) {
try { try {
container.mappedProps = mapStateToProps(currentGlobal, props, container.detachWhenChanged); container.mappedProps = mapStateToProps(currentGlobal, props, container.detachWhenChanged);
} catch (err: any) { } catch (err: any) {
handleError(err); handleError(err);
} }
} }
}
// eslint-disable-next-line react/jsx-props-no-spreading // eslint-disable-next-line react/jsx-props-no-spreading
return <Component {...container.mappedProps} {...props} />; return <Component {...container.mappedProps} {...props} />;