-
Notifications
You must be signed in to change notification settings - Fork 672
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
152 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { EnvironmentProviders, Provider, makeEnvironmentProviders } from '@angular/core'; | ||
import { RouteReuseStrategy } from '@angular/router'; | ||
|
||
import { REUSE_TAB_CACHED_MANAGER, ReuseTabCachedManagerFactory } from './reuse-tab.cache'; | ||
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'; | ||
|
||
export enum ReuseTabFeatureKind { | ||
Cache, | ||
Store | ||
} | ||
|
||
export interface ReuseTabFeature<KindT extends ReuseTabFeatureKind> { | ||
ɵkind: KindT; | ||
ɵproviders: Provider[]; | ||
} | ||
|
||
function makeFeature<KindT extends ReuseTabFeatureKind>(kind: KindT, providers: Provider[]): ReuseTabFeature<KindT> { | ||
return { | ||
ɵkind: kind, | ||
ɵproviders: providers | ||
}; | ||
} | ||
|
||
/** | ||
* Configures reuse-tab to be available for injection. | ||
* | ||
* @see {@link withLocalStorage} | ||
* @see {@link withCache} | ||
*/ | ||
export function provideReuseTabConfig(options?: { | ||
storeKey?: string; | ||
cache?: ReuseTabFeature<ReuseTabFeatureKind.Cache>; | ||
store?: ReuseTabFeature<ReuseTabFeatureKind.Store>; | ||
}): EnvironmentProviders { | ||
return makeEnvironmentProviders([ | ||
{ | ||
provide: REUSE_TAB_STORAGE_KEY, | ||
useValue: options?.storeKey ?? '_reuse-tab-state' | ||
}, | ||
(options?.cache ?? withCache()).ɵproviders, | ||
(options?.store ?? withLocalStorage()).ɵproviders, | ||
{ | ||
provide: RouteReuseStrategy, | ||
useClass: ReuseTabStrategy, | ||
deps: [ReuseTabService] | ||
} | ||
]); | ||
} | ||
|
||
export function withLocalStorage(): ReuseTabFeature<ReuseTabFeatureKind.Store> { | ||
return makeFeature(ReuseTabFeatureKind.Store, [ | ||
{ | ||
provide: REUSE_TAB_STORAGE_STATE, | ||
useFactory: () => new ReuseTabLocalStorageState() | ||
} | ||
]); | ||
} | ||
|
||
export function withCache(): ReuseTabFeature<ReuseTabFeatureKind.Cache> { | ||
return makeFeature(ReuseTabFeatureKind.Cache, [ | ||
{ | ||
provide: REUSE_TAB_CACHED_MANAGER, | ||
useFactory: () => new ReuseTabCachedManagerFactory() | ||
} | ||
]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.