<commit_before>module ImprovedInitiative {
    function getCounts<T extends Listable>(items: Listing<T>[]) {
        const localCount = items.filter(c => c.Origin === "localStorage").length;
        const accountCount = items.filter(c => c.Origin === "account").length;
        return `${localCount} local, ${accountCount} synced`;
    }
    export class AccountViewModel {
        constructor(private libraries: Libraries){}

        IsLoggedIn = env.IsLoggedIn;
        HasStorage = env.HasStorage;
        PatreonLoginUrl = env.PatreonLoginUrl;
        
        SyncedCreatures = ko.computed(() => getCounts(this.libraries.NPCs.StatBlocks()));
        SyncedPlayers = ko.computed(() => getCounts(this.libraries.PCs.StatBlocks()));
        SyncedSpells = ko.computed(() => getCounts(this.libraries.Spells.Spells()));
        SyncedEncounters = ko.computed(() => getCounts(this.libraries.Encounters.Encounters()));

        SyncAll() {
            this.SyncError("");
            var blob = Store.ExportAll();
            //saveAs(blob, 'improved-initiative.json');
            new AccountClient().SaveAll(this.libraries, err => {
                this.SyncError(this.SyncError() + "\n" + JSON.stringify(err));
            });
        };

        SyncError = ko.observable("");
    }
}<commit_msg>Export data before syncing<commit_after>module ImprovedInitiative {
    function getCounts<T extends Listable>(items: Listing<T>[]) {
        const localCount = items.filter(c => c.Origin === "localStorage").length;
        const accountCount = items.filter(c => c.Origin === "account").length;
        return `${localCount} local, ${accountCount} synced`;
    }
    export class AccountViewModel {
        constructor(private libraries: Libraries){}

        IsLoggedIn = env.IsLoggedIn;
        HasStorage = env.HasStorage;
        PatreonLoginUrl = env.PatreonLoginUrl;
        
        SyncedCreatures = ko.computed(() => getCounts(this.libraries.NPCs.StatBlocks()));
        SyncedPlayers = ko.computed(() => getCounts(this.libraries.PCs.StatBlocks()));
        SyncedSpells = ko.computed(() => getCounts(this.libraries.Spells.Spells()));
        SyncedEncounters = ko.computed(() => getCounts(this.libraries.Encounters.Encounters()));

        SyncAll() {
            this.SyncError("");
            var blob = Store.ExportAll();
            saveAs(blob, 'improved-initiative.json');
            new AccountClient().SaveAll(this.libraries, err => {
                this.SyncError(this.SyncError() + "\n" + JSON.stringify(err));
            });
        };

        SyncError = ko.observable("");
    }
}
{'fraction_non_alphanumeric': 0.14817658349328214, 'fraction_numerical': 0.0, 'mean_word_length': 2.755043227665706, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, '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': '911128', 'n_tokens_mistral': 764, 'n_tokens_neox': 748, 'n_words': 125}