<commit_before>import { Action, ActionReducer } from '@ngrx/store';

import * as windowsActions from '../actions/windows/windows';
import * as fromRoot from './';

export interface State {
    [id: string]: any;
}

/**
 * Metareducer to add new window and pass the correct window state to the main reducer
 * @param reducer
 */
export function windows(reducer: ActionReducer<any>) {
    const initKey = `__x__`;
    const initWindowState = reducer(undefined, {type: '___INIT___'});
    const initialState: State = {};

    return function(state = initialState, action: any) {

        const _state = Object.assign({}, state);

        switch (action.type) {
            case windowsActions.ADD_WINDOW:
                const { windowId, title } = action.payload;

                _state[windowId] = Object.assign({}, initWindowState);

                _state[windowId].layout.title = title;
                _state[windowId].windowId = windowId;

                return _state;
            case windowsActions.SET_WINDOWS:
                const windows = action.payload;

                const newWindowsState = {};
                windows.forEach(window => {
                    const windowKey = window.windowId;
                    const windowTitle = window.title;

                    // Using JSON.parse and JSON.stringify instead of Object.assign for deep cloning
                    const _windowState = JSON.parse(JSON.stringify(initWindowState));
                    _windowState.windowId = windowKey;
                    _windowState.layout.title = windowTitle;

                    newWindowsState[windowKey] = Object.assign({}, _windowState);
                });

                return newWindowsState;
            case windowsActions.REMOVE_WINDOW:
                const _windowId = action.windowId;

                if (_state[_windowId]) {
                    delete _state[_windowId];
                }
<commit_msg>Fixed object cloning bug in ADD_WINDOW reducer.<commit_after>import { Action, ActionReducer } from '@ngrx/store';

import * as windowsActions from '../actions/windows/windows';
import * as fromRoot from './';

export interface State {
    [id: string]: any;
}

/**
 * Metareducer to add new window and pass the correct window state to the main reducer
 * @param reducer
 */
export function windows(reducer: ActionReducer<any>) {
    const initKey = `__x__`;
    const initWindowState = reducer(undefined, {type: '___INIT___'});
    const initialState: State = {};

    return function(state = initialState, action: any) {

        const _state = Object.assign({}, state);

        switch (action.type) {
            case windowsActions.ADD_WINDOW:
                const { windowId, title } = action.payload;

                // Using JSON.parse and JSON.stringify instead of Object.assign for deep cloning
                _state[windowId] = JSON.parse(JSON.stringify(initWindowState));

                _state[windowId].layout.title = title;
                _state[windowId].windowId = windowId;

                return _state;
            case windowsActions.SET_WINDOWS:
                const windows = action.payload;

                const newWindowsState = {};
                windows.forEach(window => {
                    const windowKey = window.windowId;
                    const windowTitle = window.title;

                    // Using JSON.parse and JSON.stringify instead of Object.assign for deep cloning
                    const _windowState = JSON.parse(JSON.stringify(initWindowState));
                    _windowState.windowId = windowKey;
                    _windowState.layout.title = windowTitle;

                    newWindowsState[windowKey] = Object.assign({}, _windowState);
                });

                return newWindowsState;
            case windowsActions.REMOVE_WINDOW:
                const _windowId = action.windowId;

                if (_state[_windowId]) {
                    delete _state[_windowId];
                }

{'fraction_non_alphanumeric': 0.09245377311344327, 'fraction_numerical': 0.0, 'mean_word_length': 1.9520648967551621, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1047865', 'n_tokens_mistral': 1034, 'n_tokens_neox': 960, 'n_words': 261}