Skip to content

Commit

Permalink
chore: fix
Browse files Browse the repository at this point in the history
  • Loading branch information
cipchk committed Nov 12, 2023
1 parent 34fc914 commit 32cd797
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 22 deletions.
4 changes: 0 additions & 4 deletions packages/abc/reuse-tab/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,6 @@ Limiting the maximum number of reuse can reduce memory growth. There are several

Route reuse preserves uses URLs to distinguish whether the same page, and QueryString query parameters will be repeatedly misused, so not supported, and the QueryString part is forced to be ignored.

### How to persistent storage of tab

Use `provideReuseTabConfig(store: withLocalStorage())` to persist the tab to `localStorage`. If you need custom storage methods, you can override `REUSE_TAB_STORAGE_STATE`.

### Multi-application cache processing

Use `provideReuseTabConfig(storeKey: 'newKey')` Or overriding `REUSE_TAB_CACHED_MANAGER` to change the cache storage, for example when using a micro-frontend (similar to [ngx-planet](https://github.com/worktile/ngx-planet)) can rewrite cached data to `window` guaranteed data sharing.
4 changes: 0 additions & 4 deletions packages/abc/reuse-tab/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,6 @@ export class DemoComponent implements OnReuseInit, OnReuseDestroy {

复用采用URL来区分是否同一个页面,而 QueryString 查询参数很容易产生重复性误用,因此不支持查询参数,且在复用过程中会强制忽略掉 QueryString 部分。

### 如何标签持久化存储

使用 `provideReuseTabConfig(store: withLocalStorage())` 将标签持久化至 `localStorage` 当中,若需要其他存储方式,可覆盖 `REUSE_TAB_STORAGE_STATE`

### 多应用缓存处理

使用 `provideReuseTabConfig(storeKey: 'newKey')` 或通过覆盖 `REUSE_TAB_CACHED_MANAGER` 改变缓存存储 ,例如在使用微前端(类似[ngx-planet](https://github.com/worktile/ngx-planet))可以重写缓存数据到 `window` 下来实现数据共享。
4 changes: 1 addition & 3 deletions packages/abc/reuse-tab/provide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,13 @@ export function provideReuseTabConfig(options?: {
useValue: options?.storeKey ?? '_reuse-tab-state'
},
(options?.cacheManager ?? withCacheManager()).ɵproviders,
(options?.store ?? withLocalStorage()).ɵproviders,
{
provide: RouteReuseStrategy,
useClass: ReuseTabStrategy,
deps: [ReuseTabService]
}
];
if (options?.store) {
providers.push(options.store.ɵproviders);
}

return makeEnvironmentProviders(providers);
}
Expand Down
3 changes: 1 addition & 2 deletions packages/abc/reuse-tab/reuse-tab.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
ReuseTabMatchMode,
ReuseTabRouteParamMatchMode
} from './reuse-tab.interfaces';
import { ReuseTabModule } from './reuse-tab.module';
import { ReuseTabService } from './reuse-tab.service';
import { REUSE_TAB_STORAGE_STATE } from './reuse-tab.state';
import { ReuseTabStrategy } from './reuse-tab.strategy';
Expand All @@ -45,7 +44,7 @@ describe('abc: reuse-tab', () => {
declarations: [AppComponent, LayoutComponent, AComponent, BComponent, CComponent, DComponent, EComponent],
imports: [
DelonLocaleModule,
ReuseTabModule,
ReuseTabComponent,
RouterTestingModule.withRoutes(
[
{
Expand Down
17 changes: 8 additions & 9 deletions packages/abc/reuse-tab/reuse-tab.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Inject, Injectable, Injector, OnDestroy, Optional } from '@angular/core';
import { Inject, Injectable, Injector, OnDestroy } from '@angular/core';
import {
ActivatedRoute,
ActivatedRouteSnapshot,
Expand Down Expand Up @@ -369,8 +369,8 @@ export class ReuseTabService implements OnDestroy {
private injector: Injector,
private menuService: MenuService,
@Inject(REUSE_TAB_CACHED_MANAGER) private cached: ReuseTabCachedManager,
@Optional() @Inject(REUSE_TAB_STORAGE_KEY) private stateKey: string,
@Optional() @Inject(REUSE_TAB_STORAGE_STATE) private stateSrv?: ReuseTabStorageState
@Inject(REUSE_TAB_STORAGE_KEY) private stateKey: string,
@Inject(REUSE_TAB_STORAGE_STATE) private stateSrv: ReuseTabStorageState
) {
if (this.cached == null) {
this.cached = { list: [], title: {}, closable: {} };
Expand All @@ -386,12 +386,11 @@ export class ReuseTabService implements OnDestroy {
private loadState(): void {
if (!this.storageState) return;

this.cached.list =
this.stateSrv?.get(this.stateKey).map(v => ({
title: { text: v.title },
url: v.url,
position: v.position
})) ?? [];
this.cached.list = this.stateSrv.get(this.stateKey).map(v => ({
title: { text: v.title },
url: v.url,
position: v.position
}));
this._cachedChange.next({ active: 'loadState' });
}

Expand Down

0 comments on commit 32cd797

Please sign in to comment.