<commit_before>﻿
import chitu = require('chitu');
import ko = require('knockout');
import app = require('Application');
import services = require('Services/Service');
import home = require('Services/Home');
import Carousel = require('Core/Carousel');

chitu.Utility.loadjs('UI/PromotionLabel');

class IndexPage extends chitu.Page {
    private homeProductQueryArguments = {
        pageIndex: 0
    }

    private model = {
        name: ko.observable(''),
        brands: ko.observableArray(),
        advertItems: ko.observableArray(),
        homeProducts: ko.observableArray()
    };

    constructor(html) {
        super(html);

        this.findControl<chitu.ScrollView>('products').scrollLoad = IndexPage.scrollView_load;
        this.load.add(this.page_load);

        ko.applyBindings(this.model, this.element);
    }

    private static scrollView_load(sender: chitu.ScrollView, args) {
        var page = <IndexPage>sender.page;
        
        var result = home.homeProducts(page.homeProductQueryArguments.pageIndex)
            .done(function (homeProducts: Array<any>) {
                for (var i = 0; i < homeProducts.length; i++) {
                    homeProducts[i].Url = '#Home_Product_' + homeProducts[i].ProductId;
                    page.model.homeProducts.push(homeProducts[i]);
                }

                page.homeProductQueryArguments.pageIndex++;
                args.enableScrollLoad = (homeProducts.length == services.defaultPageSize);
            });

        return result;
    }

    private page_load(sender: IndexPage, args) {
        return home.advertItems().done(function (advertItems) {
            for (var i = 0; i < advertItems.length; i++) {
                advertItems[i].index = i;
                advertItems[i].LinkUrl = advertItems[i].LinkUrl;
                sender.model.advertItems.push(advertItems[i]);
            }

            var c = new Carousel($(sender.element).find('[name="ad-swiper"]')[0]);
        });
    }
}

export = IndexPage;<commit_msg>使用 ScrollBottomLoad 类加载数据<commit_after>﻿
import chitu = require('chitu');
import ko = require('knockout');
import app = require('Application');
import services = require('Services/Service');
import home = require('Services/Home');
import Carousel = require('Core/Carousel');
import ScrollBottomLoad = require('Core/ScrollBottomLoad');

chitu.Utility.loadjs('UI/PromotionLabel');

class IndexPage extends chitu.Page {
    private homeProductQueryArguments = {
        pageIndex: 0
    }

    private model = {
        name: ko.observable(''),
        brands: ko.observableArray(),
        advertItems: ko.observableArray(),
        homeProducts: ko.observableArray()
    };

    private scrollBottomLoad: ScrollBottomLoad;

    constructor(html) {
        super(html);

        let productsView = this.findControl<chitu.ScrollView>('products');
        this.load.add(this.page_load);

        ko.applyBindings(this.model, this.element);
        this.scrollBottomLoad = new ScrollBottomLoad(productsView, IndexPage.scrollView_load);
        IndexPage.scrollView_load(productsView, {});
    }

    private static scrollView_load(sender: chitu.ScrollView, args) {
        var page = <IndexPage>sender.page;

        var result = home.homeProducts(page.homeProductQueryArguments.pageIndex)
            .done(function (homeProducts: Array<any>) {
                for (var i = 0; i < homeProducts.length; i++) {
                    homeProducts[i].Url = '#Home_Product_' + homeProducts[i].ProductId;
                    page.model.homeProducts.push(homeProducts[i]);
                }

                page.homeProductQueryArguments.pageIndex++;
                page.scrollBottomLoad.enableScrollLoad = (homeProducts.length == services.defaultPageSize);
            });

        return result;
    }

    private page_load(sender: IndexPage, args) {
        return home.advertItems().done(function (advertItems) {
            for (var i = 0; i < advertItems.length; i++) {
                advertItems[i].index = i;
                advertItems[i].LinkUrl = advertItems[i].LinkUrl;
                sender.model.advertItems.push(advertItems[i]);
            }

            var c = new Carousel($(sender.element).find('[name="ad-swiper"]')[0]);
        });
    }
}

export = IndexPage;
{'fraction_non_alphanumeric': 0.12727272727272726, 'fraction_numerical': 0.0018648018648018648, 'mean_word_length': 2.6058823529411765, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, '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': '898401', 'n_tokens_mistral': 1251, 'n_tokens_neox': 1203, 'n_words': 215}