<commit_before>import Navigation = require('navigation');
import Rx = require('rx');

function navigate(e) {
    var historyAction = e.historyAction;
    if (typeof historyAction === 'string')
        historyAction = Navigation.HistoryAction[historyAction];
    if (e.action)
        Navigation.StateController.navigate(e.action, e.toData, historyAction);
    if (!e.action && e.toData)
        Navigation.StateController.refresh(e.toData, historyAction);
    if (e.distance)
        Navigation.StateController.navigateBack(e.distance, historyAction);
    if (e.url)
        Navigation.StateController.navigateLink(e.url, false, historyAction);
}

function isolate(NavigationSource, key) {
    var navigated$ = NavigationSource.navigated
        .filter((context) => context.state.parent.index + '-' + context.state.index === key);
    return {
        navigated: navigated$    
    };
}

var NavigationDriver = (url) => {
    return (navigate$) => {
        var started = false;
        navigate$.subscribe(e => {
            if (!started) {
                Navigation.start(url);
                started = true;
                return;
            }
            if (e.target) {
                if (!e.ctrlKey && !e.shiftKey && !e.metaKey && !e.altKey && !e.button) {
                    e.preventDefault();
                    var link = Navigation.settings.historyManager.getUrl(e.target);
                    Navigation.StateController.navigateLink(link, false, +e.target.getAttribute('data-history-action'));
                }
            } else {
                navigate(e);
            }
        });
        var navigated$ = new Rx.ReplaySubject(1);
        Navigation.StateController.onNavigate(() => navigated$.onNext(Navigation.StateContext));
        return {
            navigated: navigated$,
            isolateSource: isolate
        };
    };
}
export = NavigationDriver;<commit_msg>Used StateContext state for started check<commit_after>import Navigation = require('navigation');
import Rx = require('rx');

function navigate(e) {
    var historyAction = e.historyAction;
    if (typeof historyAction === 'string')
        historyAction = Navigation.HistoryAction[historyAction];
    if (e.action)
        Navigation.StateController.navigate(e.action, e.toData, historyAction);
    if (!e.action && e.toData)
        Navigation.StateController.refresh(e.toData, historyAction);
    if (e.distance)
        Navigation.StateController.navigateBack(e.distance, historyAction);
    if (e.url)
        Navigation.StateController.navigateLink(e.url, false, historyAction);
}

function isolate(NavigationSource, key) {
    var navigated$ = NavigationSource.navigated
        .filter((context) => context.state.parent.index + '-' + context.state.index === key);
    return {
        navigated: navigated$    
    };
}

var NavigationDriver = (url) => {
    return (navigate$) => {
        navigate$.subscribe(e => {
            if (!Navigation.StateContext.state)
                Navigation.start(url);
            if (e.target) {
                if (!e.ctrlKey && !e.shiftKey && !e.metaKey && !e.altKey && !e.button) {
                    e.preventDefault();
                    var link = Navigation.settings.historyManager.getUrl(e.target);
                    Navigation.StateController.navigateLink(link, false, +e.target.getAttribute('data-history-action'));
                }
            } else {
                navigate(e);
            }
        });
        var navigated$ = new Rx.ReplaySubject(1);
        Navigation.StateController.onNavigate(() => navigated$.onNext(Navigation.StateContext));
        return {
            navigated: navigated$,
            isolateSource: isolate
        };
    };
}
export = NavigationDriver;
{'fraction_non_alphanumeric': 0.12776740464123768, 'fraction_numerical': 0.0005334755934915977, 'mean_word_length': 2.295254833040422, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '4111532', 'n_tokens_mistral': 1046, 'n_tokens_neox': 999, 'n_words': 186}