import { defaultConfiguration } from './reducers';
const CURRENT_VERSION = 1;

export function serialize(state) {
  return JSON.stringify({
    version: CURRENT_VERSION,
    configuration: {
      editor: state.configuration.editor,
      theme: state.configuration.theme,
    },
    code: state.code,
  });
}

export function deserialize(savedState) {
  if (!savedState) { return undefined; }
  const parsedState = JSON.parse(savedState);
  if (parsedState.version != CURRENT_VERSION) { return undefined; }

  return {
    configuration: {
      ...defaultConfiguration,
      editor: parsedState.configuration.editor || defaultConfiguration.editor,
      theme: parsedState.configuration.theme || defaultConfiguration.theme,
    },
    code: parsedState.code,
  };
}

import { defaultConfiguration } from './reducers';
const CURRENT_VERSION = 1;

export function serialize(state) {
  return JSON.stringify({
    version: CURRENT_VERSION,
    configuration: {
      editor: state.configuration.editor,
      theme: state.configuration.theme,
    },
    code: state.code,
  });
}

export function deserialize(savedState) {
  if (!savedState) { return undefined; }
  const parsedState = JSON.parse(savedState);
  if (parsedState.version !== CURRENT_VERSION) { return undefined; }

  return {
    configuration: {
      ...defaultConfiguration,
      editor: parsedState.configuration.editor || defaultConfiguration.editor,
      theme: parsedState.configuration.theme || defaultConfiguration.theme,
    },
    code: parsedState.code,
  };
}

Use proper equality operator