{"library":"redux-freeze","title":"Redux State Freeze Middleware","description":"Redux-freeze is a Redux middleware designed to prevent accidental state mutations within a Redux application by deeply freezing the state object after each dispatched action. This mechanism helps enforce the core Redux principle of immutability during development, throwing a runtime error if any part of the state is modified directly. It is intended strictly as a development-time tool to catch bugs early, as its deep freezing operation introduces performance overhead unsuitable for production environments. The package is currently at version 0.1.7. Based on the lack of recent activity and a last commit several years ago, the project appears to be abandoned, with no active release cadence. Its primary differentiator is its straightforward, single-purpose approach to ensuring immutability, making it a clear diagnostic tool for identifying unintentional side effects in state management.","language":"javascript","status":"abandoned","last_verified":"Thu Apr 23","install":{"commands":["npm install redux-freeze"],"cli":null},"imports":["import freeze from 'redux-freeze';","const freeze = require('redux-freeze');","import { createStore, applyMiddleware } from 'redux';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { createStore, applyMiddleware } from 'redux';\nimport freeze from 'redux-freeze'; // Or `const freeze = require('redux-freeze');` for CJS\n\n// A basic reducer to demonstrate state mutation\nconst initialState = {\n  user: {\n    name: 'Alice',\n    preferences: { theme: 'dark' }\n  },\n  items: []\n};\n\nfunction rootReducer(state = initialState, action) {\n  switch (action.type) {\n    case 'UPDATE_USER_NAME_MUTATE':\n      // This line intentionally mutates the state, which redux-freeze will catch\n      state.user.name = action.payload; \n      return state;\n    case 'ADD_ITEM':\n      return {\n        ...state,\n        items: [...state.items, action.payload]\n      };\n    default:\n      return state;\n  }\n}\n\n// Create the Redux store with redux-freeze middleware\n// In a real application, you would typically only apply this in development mode.\nconst store = createStore(rootReducer, applyMiddleware(freeze));\n\nconsole.log('Initial state:', store.getState());\n\ntry {\n  console.log('\\nAttempting to dispatch an action that mutates state...');\n  store.dispatch({ type: 'UPDATE_USER_NAME_MUTATE', payload: 'Bob' });\n} catch (error) {\n  console.error('ERROR: Caught expected state mutation error:', error.message);\n  // Expected: \"Cannot assign to read only property 'name' of object '#<Object>'\"\n}\n\nconsole.log('\\nDispatching an action that correctly updates state immutably...');\nstore.dispatch({ type: 'ADD_ITEM', payload: { id: 1, name: 'New Item' } });\n\nconsole.log('State after immutable update:', store.getState());\n\n// Demonstrating that the retrieved state is also frozen\ntry {\n  console.log('\\nAttempting to mutate state directly after retrieval...');\n  store.getState().user.preferences.theme = 'light';\n} catch (error) {\n  console.error('ERROR: Caught expected mutation error on retrieved state:', error.message);\n}\n","lang":"typescript","description":"This quickstart demonstrates how to integrate `redux-freeze` into a Redux store and shows how it catches both direct state mutations within reducers and mutations on state objects retrieved from the store.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}