How to use ngrx-store-localstorage - 10 common examples

To help you get started, we’ve selected a few ngrx-store-localstorage examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cloudfoundry / stratos / src / frontend / packages / store / src / reducers.module.ts View on Github external
export function localStorageSyncReducer(reducer: ActionReducer): ActionReducer {
  // This is done to ensure we don't accidentally apply state from session storage from another user.
  let globalUserId = null;
  return localStorageSync({
    storageKeySerializer: (id) => {
      return globalUserId || id;
    },
    syncCondition: () => {
      if (globalUserId) {
        return true;
      }
      const userId = getDashboardStateSessionId();
      if (userId) {
        globalUserId = userId;
        return true;
      }
      return false;
    },
    keys: ['dashboard'],
    rehydrate: false,
github orizens / echoes-player / src / app / core / store / index.ts View on Github external
import { combineReducers } from '@ngrx/store';
import { compose } from '@ngrx/core/compose';
import { StoreDevtoolsModule } from '@ngrx/store-devtools';
import { getSidebarExpanded } from './app-layout';
import { storeRegistry, registerReducers } from './store.registry';

import { reducersRegisters, EchoesState } from './reducers';

import { localStorageSync } from 'ngrx-store-localstorage';

export { EchoesState } from './reducers';
const { actions, reducers } = registerReducers(reducersRegisters);

const composeStore = compose(
  localStorageSync(['videos', 'player', 'nowPlaylist', 'search', 'appLayout'], true),
  combineReducers
)(reducers);

const optionalImports = [];

if ('production' !== ENV) {
    // Note that you must instrument after importing StoreModule
    // optionalImports.push(StoreDevtoolsModule.instrumentOnlyWithExtension());
}
@NgModule({
  imports: [
    StoreModule.provideStore(composeStore),
    ...optionalImports
  ],
  declarations: [],
  exports: [],
github new-eden-social / new-eden-social / src / web / src / app / app.store.ts View on Github external
export function localStorage(reducer: ActionReducer): ActionReducer {
  return localStorageSync({
    // Only store authentication
    keys: ['authentication'],
    rehydrate: true,
  })(reducer);
}
github SAP / cloud-commerce-spartacus-storefront / src / app / routing / store / reducers / store-sync.reducer.ts View on Github external
return function(reducer: ActionReducer): ActionReducer {
    return localStorageSync(storage)(reducer);
  };
}
github SAP / cloud-commerce-spartacus-storefront / projects / storefrontlib / src / lib / routing / store / reducers / store-sync.reducer.ts View on Github external
return function(reducer: ActionReducer): ActionReducer {
    return localStorageSync(storage)(reducer);
  };
}
github PierreRochard / general-angular / src / app / app.reducers.ts View on Github external
export function localStorageSyncReducer(reducer: ActionReducer): ActionReducer {
   return localStorageSync(localStorageConfig)(reducer);
}
github bkorobeinikov / movieapp-ionic / src / store / reducers / index.ts View on Github external
ticket: fromTicket.reducer,
    account: fromAccount.reducer,
};

function applyDefaultState(reducer: ActionReducer): ActionReducer {
    const INITIAL_STATE = '@ngrx/store/init';

    return (state: State, action: Action): State => {
        if (action.type == INITIAL_STATE)
            state = _.merge({}, initialState, state);

        return reducer(state, action);
    };
}

const withLocalStorage = localStorageSync([
    { movie: ["entities", "mapMovieToCinema"] },
    { cinema: ["cinemas", "currentCinemaId", "screenings"] },
    { ticket: ["tickets"] },
    { account: ["account", "auth"] }],
    true);

const devReducer: ActionReducer = compose(withLocalStorage, applyDefaultState, storeFreeze, combineReducers)(reducers);
const prodReducer: ActionReducer = compose(withLocalStorage, applyDefaultState, combineReducers)(reducers);

export function reducer(state: State, action: any) {
    const production = false;

    if (production)
        return prodReducer(state, action);
    else
        return devReducer(state, action);
github orizens / echoes-player / src / app / core / store / index.ts View on Github external
export function localStorageSyncReducer(
  reducer: ActionReducer
): ActionReducer {
  return localStorageSync({
    keys: Object.keys(EchoesReducers),
    rehydrate: true
  })(reducer);
}
const metaReducers: MetaReducer[] = [localStorageSyncReducer];
github SAP / cloud-commerce-spartacus-storefront / projects / core / src / state / reducers / store-sync.reducer.ts View on Github external
return function(
    reducer: ActionReducer
  ): ActionReducer {
    return localStorageSync(storage)(reducer);
  };
}
github typebytes / angular-checklist / src / app / state / app.state.ts View on Github external
export function localStorageSyncReducer(reducer: ActionReducer): ActionReducer {
  return localStorageSync({ keys: ['projects'], rehydrate: true })(reducer);
}

ngrx-store-localstorage

State and local storage syncing for @ngrx/store

MIT
Latest version published 5 months ago

Package Health Score

76 / 100
Full package analysis