Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add callback to action ComponentWillUnmount #121

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,630 changes: 1,330 additions & 1,300 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/counter-example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/redux-dynamic-modules-core/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 17 additions & 5 deletions packages/redux-dynamic-modules-react/src/DynamicModuleLoader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface IDynamicModuleLoaderProps {
*/
export class DynamicModuleLoader extends React.Component<
IDynamicModuleLoaderProps
> {
> {
public render() {
return (
<ReactReduxContext.Consumer>
Expand All @@ -47,6 +47,8 @@ export class DynamicModuleLoader extends React.Component<
}

interface IDynamicModuleLoaderImplProps extends IDynamicModuleLoaderProps {
/** Callback function on action componentWillUnmount */
onUnmount?: (cleanup: () => any) => any;
/** The react-redux context passed from the <Provider> component */
reactReduxContext?: { store: IModuleStore<any> };
}
Expand All @@ -62,7 +64,7 @@ interface IDynamicModuleLoaderImplState {
class DynamicModuleLoaderImpl extends React.Component<
IDynamicModuleLoaderImplProps,
IDynamicModuleLoaderImplState
> {
> {
/** The modules that were added from this loader */
private _addedModules?: IDynamicallyAddedModule;
/** Flag that indicates we need to create a store/provider because a parent store was not provided */
Expand Down Expand Up @@ -111,7 +113,10 @@ class DynamicModuleLoaderImpl extends React.Component<
return (
<>
{this._renderLoader()}
<AddedModulesCleanup cleanup={this._cleanup} />
<AddedModulesCleanup
cleanup={this._cleanup}
onUnmount={this.props.onUnmount}
/>
</>
);
}
Expand Down Expand Up @@ -168,6 +173,7 @@ class DynamicModuleLoaderImpl extends React.Component<
}

interface IAddedModulesCleanupProps {
onUnmount?: (cleanup: () => any) => any;
cleanup: () => any;
}

Expand All @@ -184,6 +190,12 @@ class AddedModulesCleanup extends React.Component<IAddedModulesCleanupProps> {
}

public componentWillUnmount() {
this.props.cleanup();
const { cleanup, onUnmount } = this.props;

if (onUnmount) {
onUnmount(cleanup);
} else {
cleanup();
}
}
}
}
2 changes: 1 addition & 1 deletion packages/typescript-example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/widgets-example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.