I'm attempting to freeze the keys inside my object so that I don't accidentally update them, as I'm using React Native (0.34.0) and Redux, so I need to use pure functions.
However using the deepFreeze npm package, as well as trying Object.freeze(...) it still let's me mutate my keys on the following code, any help would be appreciated!
var Immutable = require('immutable');
var deepFreeze = require('deep-freeze');
import * as types from '../actions/actionTypes';
const initialState = {
customBackgroundColour: '#f7f7f7'
};
export default function backgroundColour(state = initialState, action = {}) {
switch (action.type) {
case types.SET_BACKGROUND_COLOUR:
deepFreeze(state);
deepFreeze(action);
console.log(Object.isFrozen(state)); // true
console.log(state.customBackgroundColour); // #f7f7f7
state.customBackgroundColour = 'red';
console.log(state.customBackgroundColour); // red
return {
...state,
customBackgroundColour: action.payload.colour
};
default:
return state;
}
}