Skip to content

Commit

Permalink
Tweak PersistenceProvider types (#3896)
Browse files Browse the repository at this point in the history
  • Loading branch information
ghsolomon authored Jan 14, 2025
1 parent ac70348 commit 5624969
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions core/persist/PersistenceProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,17 @@ export abstract class PersistenceProvider<S> {

private disposer: IReactionDisposer;

private static readonly PROVIDERS: Record<PersistenceProviderType, typeof PersistenceProvider> =
{
pref: PrefProvider,
localStorage: LocalStorageProvider,
sessionStorage: SessionStorageProvider,
dashView: DashViewProvider,
viewManager: ViewManagerProvider,
custom: CustomProvider
};
private static readonly PROVIDERS: Record<
PersistenceProviderType,
new <S>(cfg: PersistenceProviderConfig<S>) => PersistenceProvider<S>
> = {
pref: PrefProvider,
localStorage: LocalStorageProvider,
sessionStorage: SessionStorageProvider,
dashView: DashViewProvider,
viewManager: ViewManagerProvider,
custom: CustomProvider
};

/**
* Register a custom `PersistenceProvider` subclass for use by the {@link create} factory called
Expand All @@ -87,7 +89,10 @@ export abstract class PersistenceProvider<S> {
* @param type - provider identifier to support as a `PersistOptions.type` value.
* @param provider - the custom provider class to instantiate.
*/
static registerType(type: PersistenceProviderType, provider: typeof PersistenceProvider) {
static registerType(
type: PersistenceProviderType,
provider: new <S>(cfg: PersistenceProviderConfig<S>) => PersistenceProvider<S>
) {
this.PROVIDERS[type] = provider;
}

Expand Down Expand Up @@ -122,10 +127,10 @@ export abstract class PersistenceProvider<S> {
if (rest.getData || rest.setData) type = 'custom';
}

const clazz = this.PROVIDERS[type] as any;
const clazz = this.PROVIDERS[type];
throwIf(!clazz, `Unknown Persistence Provider type: ${type}`);

ret = new clazz(cfg) as PersistenceProvider<S>;
ret = new clazz(cfg);
ret.bindToTarget(target);
return ret;
} catch (e) {
Expand Down

0 comments on commit 5624969

Please sign in to comment.