Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custom prefix storageKeySerializer based on app state property in feature metaReducer. #247

Open
Sireini opened this issue Mar 22, 2023 · 2 comments
Labels
feature stores Functionality related to feature stores / modules question

Comments

@Sireini
Copy link

Sireini commented Mar 22, 2023

I am trying to figure out how to create a custom prefix based on a siteId which is stored in the AppState. Could you help me out in providing the siteId of the AppState in the localStorageSyncReducer of a StoreModule.forFeature('x')?

export function localStorageSyncReducer(reducer: ActionReducer<ReadMappingState>): ActionReducer<ReadMappingState> {
    const siteId: string = 'this must be a dynamic siteId based on the site in AppState';
    return localStorageSync({
        keys: STORE_KEYS_TO_PERSIST,
        storageKeySerializer: (key) => `${siteId}_${key}`,
        rehydrate: true,
        removeOnUndefined: true,
        mergeReducer
    })(reducer);
}

This is the state module of feature X:

@NgModule({
    imports: [
        CommonModule,
        StoreModule.forFeature('x', xReducer, {
            metaReducers
        }),
        EffectsModule.forFeature([xEffects]),
    ],
    providers: [xFacade],
})
export class xStateModule { }

Would be nice if somebody could help me out :)

@Sireini
Copy link
Author

Sireini commented Mar 23, 2023

It doesn't have to be from the AppState but can also be a siteId from xFeature

@Sireini
Copy link
Author

Sireini commented Mar 24, 2023

Okay I managed to get the id in an action and save it in the localStorage based on which site is selected with the siteId prefix, but there are two problems:

  1. Both states will be overwritten with data.
  2. Rehydrating of a specific state based on the siteId is not working.

@BBlackwo BBlackwo added question feature stores Functionality related to feature stores / modules labels Apr 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature stores Functionality related to feature stores / modules question
Projects
None yet
Development

No branches or pull requests

2 participants