Skip to content

Commit

Permalink
feat(@alita/plugins): add closeAllTabs
Browse files Browse the repository at this point in the history
  • Loading branch information
Penguin-Lin committed Apr 2, 2024
1 parent 3a1a8d7 commit 573ff34
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/plugins/src/keepalive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ export function closeTab(path: string) {
path
}});
}
export function closeAllTabs() {
keepaliveEmitter.emit({type:'closeAllTabs'});
}
`,
});
// index.ts for export
Expand All @@ -102,7 +105,7 @@ export function closeTab(path: string) {
path: `${DIR_NAME}/index.tsx`,
content: `
export { KeepAliveContext,useKeepOutlets } from './context';
export { dropByCacheKey, closeTab } from './support';
export { dropByCacheKey, closeTab, closeAllTabs } from './support';
`,
});
});
Expand Down
9 changes: 9 additions & 0 deletions packages/plugins/templates/keepalive/context.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@ export function useKeepOutlets() {
navigate(`${pathname}${search}${hash}`);
}
};
const closeAllTabs = () => {
const pathList = Object.keys(keepElements.current);
pathList.forEach(targetKey => {
dropByCacheKey(targetKey?.toLowerCase());
});
};
const navigate = useNavigate();
{{#isPluginModelEnable}}
const localConfig = React.useMemo(() => {
Expand Down Expand Up @@ -275,6 +281,9 @@ export function useKeepOutlets() {
case 'closeTab':
closeTab(payload?.path?.toLowerCase());
break;
case 'closeAllTabs':
closeAllTabs();
break;
{{/hasTabsLayout}}
default:
break;
Expand Down

0 comments on commit 573ff34

Please sign in to comment.