Skip to content

Commit

Permalink
chore: add args
Browse files Browse the repository at this point in the history
  • Loading branch information
cipchk committed Nov 12, 2023
1 parent 20ab7a7 commit e1c48cc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
26 changes: 25 additions & 1 deletion packages/abc/reuse-tab/provide.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { EnvironmentProviders, Provider, makeEnvironmentProviders } from '@angular/core';
import {
ENVIRONMENT_INITIALIZER,
EnvironmentProviders,
Provider,
inject,
makeEnvironmentProviders
} from '@angular/core';
import { RouteReuseStrategy } from '@angular/router';

import { REUSE_TAB_CACHED_MANAGER, ReuseTabCachedManagerFactory } from './reuse-tab.cache';
import { ReuseTabMatchMode, ReuseTabRouteParamMatchMode } from './reuse-tab.interfaces';
import { ReuseTabService } from './reuse-tab.service';
import { REUSE_TAB_STORAGE_KEY, REUSE_TAB_STORAGE_STATE, ReuseTabLocalStorageState } from './reuse-tab.state';
import { ReuseTabStrategy } from './reuse-tab.strategy';
Expand Down Expand Up @@ -30,6 +37,11 @@ function makeFeature<KindT extends ReuseTabFeatureKind>(kind: KindT, providers:
* @see {@link withCacheManager}
*/
export function provideReuseTabConfig(options?: {
debug?: boolean;
mode?: ReuseTabMatchMode;
routeParamMatchMode?: ReuseTabRouteParamMatchMode;
max?: number;
excludes?: RegExp[];
storeKey?: string;
cacheManager?: ReuseTabFeature<ReuseTabFeatureKind.CacheManager>;
store?: ReuseTabFeature<ReuseTabFeatureKind.Store>;
Expand All @@ -45,6 +57,18 @@ export function provideReuseTabConfig(options?: {
provide: RouteReuseStrategy,
useClass: ReuseTabStrategy,
deps: [ReuseTabService]
},
{
provide: ENVIRONMENT_INITIALIZER,
multi: true,
useValue: () => {
const srv = inject(ReuseTabService);
if (options?.debug) srv.debug = options.debug;
if (options?.mode) srv.mode = options.mode;
if (options?.routeParamMatchMode) srv.routeParamMatchMode = options.routeParamMatchMode;
if (options?.max) srv.max = options.max;
if (options?.excludes) srv.excludes = options.excludes;
}
}
];

Expand Down
2 changes: 1 addition & 1 deletion src/app/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,6 @@ export const appConfig: ApplicationConfig = {
// Elements
importProvidersFrom(ServiceWorkerModule.register('ngsw-worker.js', { enabled: environment.production })),
provideElements()
// provideReuseTabConfig()
// provideReuseTabConfig({ max: 2 })
]
};

0 comments on commit e1c48cc

Please sign in to comment.