<commit_before>import {EventEmitter} from 'events';
import appDispatcher from '../dispatchers/appDispatcher';

class LocationStore extends EventEmitter {
    constructor() {
        super();

        this._state = {
            page: 'index',
            data: null
        };

        if (typeof window !== 'undefined'){
            if (window.__locationState) {
                this._state = window.__locationState;
            }

            if (typeof window.onpopstate !== 'undefined') {
                window.addEventListener('popstate', () => {
                    var newState = parsePath(String(window.location.pathname));
                    this._navigate(newState, false);
                })
            }
        }

        appDispatcher.register(this._onDispatch.bind(this));
    }

    _onDispatch(payload) {
        if (payload.action === 'NAVIGATE') {
            this._navigate(payload, true);
        }
        if (payload.action === 'NAVIGATE_TO_PATH') {
            this._navigate(parsePath(payload.path), true);
        }
    }

    _navigate(newState, pushToHistory) {
        if (this._state.page !== newState.page || this._state.data !== newState.data) {
            this._state = newState;
            if (typeof document !== 'undefined') {
                document.title = this.getTitle();
            }
            if (pushToHistory &&
                typeof window !== 'undefined' &&
                typeof window.history.pushState !== 'undefined'
            ) {
                try {
                    window.history.pushState(null, this.getTitle(), this.renderPath(
                        newState.page, newState.data
                    ));
                } catch (e) {} // Can fail on file:// origins
            }
            this.emit('change');
        }
    }

    getPage() {
        return this._state.page;
    }

    getData() {
        return this._state.data;
    }

    renderPath(page, data, extension) {
        var pathToRoot = this._state.data ? '../' : './';
        if (page === 'index') {
            return pathToRoot;
        } else {
            return pathToRoot + page + (data ? '/' + data : '') + (extension || '.html');
        }
    }

    getTitle() {
        var page = this._state.page;
        if (page === 'index') {<commit_msg>Fix push state issue<commit_after>import {EventEmitter} from 'events';
import appDispatcher from '../dispatchers/appDispatcher';

class LocationStore extends EventEmitter {
    constructor() {
        super();

        this._state = {
            page: 'index',
            data: null
        };

        if (typeof window !== 'undefined'){
            if (window.__locationState) {
                this._state = window.__locationState;
            }

            if (typeof window.onpopstate !== 'undefined') {
                window.addEventListener('popstate', () => {
                    var newState = parsePath(String(window.location.pathname));
                    this._navigate(newState, false);
                })
            }
        }

        appDispatcher.register(this._onDispatch.bind(this));
    }

    _onDispatch(payload) {
        if (payload.action === 'NAVIGATE') {
            this._navigate(payload, true);
        }
        if (payload.action === 'NAVIGATE_TO_PATH') {
            this._navigate(parsePath(payload.path), true);
        }
    }

    _navigate(newState, pushToHistory) {
        if (this._state.page !== newState.page || this._state.data !== newState.data) {
            var newPath = this.renderPath(
                newState.page, newState.data
            );
            this._state = newState;
            if (typeof document !== 'undefined') {
                document.title = this.getTitle();
            }
            if (pushToHistory &&
                typeof window !== 'undefined' &&
                typeof window.history.pushState !== 'undefined'
            ) {
                try {
                    window.history.pushState(null, this.getTitle(), newPath);
                } catch (e) {} // Can fail on file:// origins
            }
            this.emit('change');
        }
    }

    getPage() {
        return this._state.page;
    }

    getData() {
        return this._state.data;
    }

    renderPath(page, data, extension) {
        var pathToRoot = this._state.data ? '../' : './';
        if (page === 'index') {
            return pathToRoot;
        } else {
            return pathToRoot + page + (data ? '/' + data : '') + (extension || '.html');
        }
    }

    getTitle() {
        var page = this._state.page;
        if (page === 'index') {
{'fraction_non_alphanumeric': 0.1337083513630463, 'fraction_numerical': 0.0, 'mean_word_length': 1.523471615720524, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6584701', 'n_tokens_mistral': 1252, 'n_tokens_neox': 1206, 'n_words': 242}