ngrx-store-freeze修改数字字段时未抛出错误的问题咨询
ngrx-store-freeze: How It Works & Why Numeric Field Changes Don’t Trigger Errors
Let me walk through what ngrx-store-freeze does, its official behavior, and why you’re seeing no errors when modifying numeric state fields:
- Core Role: This meta-reducer exists to block accidental mutation of existing state objects — it’s not focused on enforcing the creation of new objects, but rather ensuring you don’t alter state in-place. Its main goal is to keep your state immutable during development.
- Official Behavior (per its documentation):
ngrx-store-freeze is a meta-reducer that prevents state mutation. It recursively freezes the current state, the dispatched action's payload (if present), and the new state. It will throw an exception if any mutation occurs, and should only be used in development to ensure state remains immutable.
- Why Numeric Fields Don’t Trigger Errors: The key here is JavaScript’s primitive values (numbers, strings, booleans, etc.) are inherently immutable. When you "update" a numeric state property, you’re not modifying the original number — you’re replacing it with an entirely new numeric value. Since no in-place mutation of the state object or its properties is happening,
ngrx-store-freezedoesn’t detect a violation, so it won’t throw an error.
内容的提问来源于stack exchange,提问作者sashoalm
相关产品推荐
相关产品推荐

