Skip to content

Commit

Permalink
feat(@alita/plugins): add closeAllTabs
Browse files Browse the repository at this point in the history
closeAllTabs can be used to close all keepalive tabs
  • Loading branch information
Penguin-Lin committed Apr 1, 2024
1 parent 20e3818 commit 3a1a8d7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/red-fishes-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@alita/plugins': patch
---

closeAllTabs can be used to close all keepalive tabs
5 changes: 1 addition & 4 deletions packages/plugins/src/keepalive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,6 @@ export function closeTab(path: string) {
path
}});
}
export function closeAllTabs() {
keepaliveEmitter.emit({type:'closeAllTabs'});
}
`,
});
// index.ts for export
Expand All @@ -105,7 +102,7 @@ export function closeAllTabs() {
path: `${DIR_NAME}/index.tsx`,
content: `
export { KeepAliveContext,useKeepOutlets } from './context';
export { dropByCacheKey, closeTab, closeAllTabs } from './support';
export { dropByCacheKey, closeTab } from './support';
`,
});
});
Expand Down
9 changes: 0 additions & 9 deletions packages/plugins/templates/keepalive/context.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,6 @@ 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 @@ -281,9 +275,6 @@ export function useKeepOutlets() {
case 'closeTab':
closeTab(payload?.path?.toLowerCase());
break;
case 'closeAllTabs':
closeAllTabs();
break;
{{/hasTabsLayout}}
default:
break;
Expand Down

0 comments on commit 3a1a8d7

Please sign in to comment.