<commit_before>import * as React from 'react';
import { newObject } from '../ts/onClickUtils';

export default abstract class Component<P, S> extends React.Component<P, S> {
    async setStateAsync(newState: S): Promise<any> {
        return new Promise((resolve, reject) => {
            this.setState(newState, () => {
                resolve();
            });
        });
    }

    updateState(key: keyof S, value: S[keyof S]) {
        const update: any = {};
        update[key] = value;
        this.setState(newObject(this.state, update));
    }

    async updateStateAsync(key: keyof S, value: S[keyof S]) {
        const update: any = {};
        update[key] = value;
        await this.setStateAsync(newObject(this.state, update));
    }
}<commit_msg>Add redirect checking in constructor of Component<commit_after>import * as React from 'react';
import { newObject } from '../ts/onClickUtils';
import { AuthState } from '../ts/authState';
import { browserHistory } from 'react-router';

export default abstract class Component<P, S> extends React.Component<P, S> {
    async setStateAsync(newState: S): Promise<any> {
        return new Promise((resolve, reject) => {
            this.setState(newState, () => {
                resolve();
            });
        });
    }

    updateState(key: keyof S, value: S[keyof S]) {
        const update: any = {};
        update[key] = value;
        this.setState(newObject(this.state, update));
    }

    async updateStateAsync(key: keyof S, value: S[keyof S]) {
        const update: any = {};
        update[key] = value;
        await this.setStateAsync(newObject(this.state, update));
    }

    constructor(props: P) {
        super(props);
        const p: { location?: { pathname: string }} = props;
        AuthState.getInstance().updateState().then(s => {
            if (s.isNothing() && p.location && p.location.pathname !== '/') {
                browserHistory.push('/');
                return;
            }
        });
    }
}
{'fraction_non_alphanumeric': 0.1465, 'fraction_numerical': 0.0, 'mean_word_length': 2.323920265780731, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 14, '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': '3500119', 'n_tokens_mistral': 577, 'n_tokens_neox': 574, 'n_words': 142}