<commit_before>import debug from "debug";
import data from "../../data/schedule";
import React from "react";
import { App } from "./components/app";

const log = debug("app:app");

const initialState = {
    main: {
        view: "default"
    },
    time: {
        now: new Date()
    },
    update: {
        available: false
    }
};

let currentState = initialState;

function getState() {
    return { ...currentState };
}

function updateState(branch, patch) {
    if ("." === branch) {
        currentState = { ...currentState, ...patch };
    } else {
        currentState = { ...currentState, [branch]: patch };
    }

    return getState();
}

function renderMain(props) {
    React.render(
        React.createElement(App, props),
        document.querySelector("body")
    );
}

export function start() {
    // Wrapped update so state updates re-render the app
    let wrappedUpdate = (...update) => {
        updateState(...update);
        renderMain({ getState, updateState: wrappedUpdate });
    };

    // Really ugly hack to include the date in the session start time
    Object.keys(data.days).forEach(d => {
        Object.keys(data.days[d].tracks).forEach(t => {
            data.days[d].tracks[t].forEach(s => {
                s.start = new Date(d + " " + s.start);
            });
        });
    });

    let updateTimer = () => {
        wrappedUpdate("time", { now: new Date() });

        setTimeout(updateTimer, 1000);
    };

    wrappedUpdate(".", { ...initialState, ...data });
    updateTimer();

    // Subscribe to AppCache events so we can show a notice
    // if an update is available

    window.applicationCache.addEventListener(
        "updateready",
        () => wrappedUpdate("update", { available: true }),
        false);
}
<commit_msg>Add today into app state<commit_after>import debug from "debug";
import data from "../../data/schedule";
import React from "react";
import { App } from "./components/app";

const log = debug("app:app");

const initialState = {
    main: {
        view: "default"
    },
    time: {
        today: new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate()),
        now: new Date()
    },
    update: {
        available: false
    }
};

let currentState = initialState;

function getState() {
    return { ...currentState };
}

function updateState(branch, patch) {
    if ("." === branch) {
        currentState = { ...currentState, ...patch };
    } else {
        currentState = { ...currentState, [branch]: patch };
    }

    return getState();
}

function renderMain(props) {
    React.render(
        React.createElement(App, props),
        document.querySelector("body")
    );
}

export function start() {
    // Wrapped update so state updates re-render the app
    let wrappedUpdate = (...update) => {
        updateState(...update);
        renderMain({ getState, updateState: wrappedUpdate });
    };

    // Really ugly hack to include the date in the session start time
    Object.keys(data.days).forEach(d => {
        Object.keys(data.days[d].tracks).forEach(t => {
            data.days[d].tracks[t].forEach(s => {
                s.start = new Date(d + " " + s.start);
            });
        });
    });

    let updateTimer = () => {
        wrappedUpdate("time", { now: new Date() });

        setTimeout(updateTimer, 1000);
    };

    wrappedUpdate(".", { ...initialState, ...data });
    updateTimer();

    // Subscribe to AppCache events so we can show a notice
    // if an update is available

    window.applicationCache.addEventListener(
        "updateready",
        () => wrappedUpdate("update", { available: true }),
        false);
}

{'fraction_non_alphanumeric': 0.15746532499320098, 'fraction_numerical': 0.0021756867011150393, 'mean_word_length': 2.272241992882562, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '2793683', 'n_tokens_mistral': 1055, 'n_tokens_neox': 1038, 'n_words': 272}