Git Product home page Git Product logo

Comments (4)

brandonroberts avatar brandonroberts commented on May 31, 2024 5

You can create a meta-reducer that wraps storeFreeze to selectively freeze based on the action type. I'm going to add a built-in API to blacklist/whitelist freezing of state in future release. Working example with current code below to ignore actions dispatched by @ngrx/router-store version 4.x.

import { Action, ActionReducer, MetaReducer } from '@ngrx/store';
import { storeFreeze } from 'ngrx-store-freeze';

export function freezer(reducer: ActionReducer<any>): ActionReducer<any> {
  const exclusions: RegExp[] = [
    /^ROUTER_/
  ];

  return function(state: any, action: Action): any {
    const excluded = exclusions.reduce((current, next) => {
      const isExcluded = Boolean(action.type.match(next));

      return current || isExcluded;
    }, false);

    if (excluded) {
      return reducer(state, action);
    }

    return storeFreeze(reducer)(state, action);
  };
}

export const metaReducers: MetaReducer<any>[] = !environment.production ? [freezer] : [];

from ngrx-store-freeze.

crysislinux avatar crysislinux commented on May 31, 2024

I have the same problem. some injectors are saved in the store. it should be mutable. I guess for those none serializable states, there is a possibility that they are mutable.

from ngrx-store-freeze.

AngelKyriako avatar AngelKyriako commented on May 31, 2024

There is no problem with saving mutable state in the store.

The problem is that you cannot deep freeze the part of state that is pure in development mode.
Thats what the issue is about.

By deactivating the deepfreeze you are good to go.

from ngrx-store-freeze.

osnoser1 avatar osnoser1 commented on May 31, 2024

I have in some of my actions a route object of the ActivatedRoute type, my solution in ngrx 7 thanks to @brandonroberts was the following:

export function freezer(reducer: ActionReducer<any>): ActionReducer<any> {
  const exclusions: RegExp[] = [/^@ngrx\/router-store\//, /^\[Router\]/];

  function hasActivatedRoute(action: Action & { payload?: any }) {
    return (action.payload && action.payload.route) || false;
  }

  return function(state: any, action: Action): any {
    const excluded = exclusions.reduce((current, next) => {
      const isExcluded = Boolean(action.type.match(next)) || hasActivatedRoute(action);
      return current || isExcluded;
    }, false);

    if (excluded) {
      return reducer(state, action);
    }

    return storeFreeze(reducer)(state, action);
  };
}

from ngrx-store-freeze.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.