<commit_before>import { Router } from '@angular/router';
import { TasselNavigationBase } from './base.component';
import { IdentityService } from './../../../services/identity/identity.service';
import { pageShowAnimation } from './../../../utils/app.utils';
import { Component, HostBinding, OnInit, ViewChild, ElementRef, AfterViewInit } from '@angular/core';

interface IPost {
    Cover?: string;
    Title: string;
    Summary?: string;
    Like: number;
    Stamp?: string;
}

interface IAdaptor {
    Col: 1 | 2 | 3 | 4;
}

@Component({
    selector: 'tassel-root-index',
    templateUrl: './../views/index.html',
    animations: [pageShowAnimation],
    styleUrls: [
        './../styles/root.css',
        './../styles/index.css',
        './../styles/card.css'
    ]
})
export class IndexComponent extends TasselNavigationBase implements OnInit, AfterViewInit {

    @HostBinding('@routeAnimation') routeAnimation = true;
    @HostBinding('style.display') display = 'block';

    @ViewChild('indexDiv') private indexDiv: ElementRef;
    @ViewChild('col01') private col01: ElementRef;
    @ViewChild('col02') private col02: ElementRef;
    @ViewChild('col03') private col03: ElementRef;
    @ViewChild('col04') private col04: ElementRef;
    private get column01() { return (this.col01 || { nativeElement: undefined }).nativeElement; }
    private get column02() { return (this.col02 || { nativeElement: undefined }).nativeElement; }
    private get column03() { return (this.col03 || { nativeElement: undefined }).nativeElement; }
    private get column04() { return (this.col04 || { nativeElement: undefined }).nativeElement; }
    private get columns(): [number, number][] {
        return [
            [0, (this.column01 || { clientHeight: 0 }).clientHeight],
            [1, (this.column02 || { clientHeight: 0 }).clientHeight],
            [2, (this.column03 || { clientHeight: 0 }).clientHeight],
            [3, (this.column04 || { clientHeight: 0 }).clientHeight]
        ];
    }

    private shouldRecheck = false;

    private _posts: IPost[] = [];
    public get Posts() { return this._posts; }

    private _bindings: IPost[][] = [[], [], [], []];
    public get Bindings() { return this._bindings; }

    private _adaptor: IAdaptor = { Col: 4 };
    public get Adaptor() { return this._adaptor; }

    constructor(
        protected identity: IdentityService,
        protected router: Router) { super(identity, router); }

    ngOnInit(): void {
        this._posts = this.postsProvide();
        this.reselectHeights(4, undefined, true);
    }

    private postsProvide = () => {
        return [
            { Cover: 'https://tse1-mm.cn.bing.net/th?id=OIP.C-XsFDZ4CpgjHkNFkqXQDAEsC7&p=0&pid=1.1', Title: '我是一只猫', Summary: '中文测试', Like: 254 },
            { Cover: 'http://p3.wmpic.me/article/2016/07/25/1469459240_PzFfSySK.jpg', Title: 'Europe Street beat', Like: 21, Stamp: 'XXXX-XX-XX' },
            { Title: '什么图片都没有', Summary: '别做梦了。', Like: 213, Stamp: 'XXXX-XX-XX' },
            { Cover: 'https://os.alipayobjects.com/rmsportal/QBnOOoLaAfKPirc.png', Title: 'Europe Street beat', Summary: 'www.instagram.com', Like: 86 },
            { Cover: 'http://i5.qhimg.com/t019c2a1cad4940cf50.jpg', Title: 'Europe Street beat', Summary: 'www.instagram.com', Like: 123 },
            { Cover: 'http://a0.att.hudong.com/70/82/01300000185479121382825220187.jpg', Title: 'Europe Street beat', Summary: 'www.instagram.com', Like: 34 },
            { Cover: 'http://free-photos-ls02.gatag.net/images/lgf01a201401230500.jpg', Title: 'Europe Street beat', Like: 23, Stamp: 'XXXX-XX-XX' },
            { Cover: 'http://pic.bizhi360.com/bpic/46/5046.jpg', Title: 'Europe Street beat', Summary: 'www.instagram.com', Like: 34, Stamp: 'XXXX-XX-XX' },
            { Cover: 'http://a4.att.hudong.com/03/27/01300000066957120529279410702.jpg', Title: 'Europe Street beat', Summary: 'www.instagram.com', Like: 341 },
            { Title: 'No Picture Test', Summary: 'Sorry, there is no picture for showing, if you want see more , close the browser and get out of home.', Like: 456 },
            { Cover: 'http://pic.7y7.com/Uploads/Former/20148/2014083037415845_0_0_water.jpg', Title: 'Something Wrong', Summary: '......', Like: 34524 },
            { Cover: 'http://uploadfile.deskcity.org/2015/0907/20150907025557427.jpg', Title: 'Europe Street beat', Summary: 'www.instagram.com', Like: 3 },
        ];
    }

    ngAfterViewInit(): void {
        this.WaitAndDo(this.rebuildView, 50);
        this.prepareScroll();
    }

    private prepareScroll = () => {
        const root = this.indexDiv.nativeElement as HTMLDivElement;
        const f_parent = root.parentElement.parentElement.parentElement;
        const that = this;
        const onScroll = function () {
            const add_height = this.scrollTop + this.clientHeight;
            if (this.scrollHeight - add_height < 100) {
                f_parent.onscroll = null;
                setTimeout(() => {
                    that.reselectHeights(that._adaptor.Col, that.postsProvide());
                    that.reselectCheck(that._adaptor.Col);
                    f_parent.onscroll = onScroll;
                }, 500);
            }
        };
        f_parent.onscroll = onScroll;
    }

    private rebuildView = async () => {<commit_msg>enable exist loop in index comp<commit_after>import { Router } from '@angular/router';
import { TasselNavigationBase } from './base.component';
import { IdentityService } from './../../../services/identity/identity.service';
import { pageShowAnimation } from './../../../utils/app.utils';
import { Component, HostBinding, OnInit, ViewChild, ElementRef, AfterViewInit, OnDestroy } from '@angular/core';

interface IPost {
    Cover?: string;
    Title: string;
    Summary?: string;
    Like: number;
    Stamp?: string;
}

interface IAdaptor {
    Col: 1 | 2 | 3 | 4;
}

@Component({
    selector: 'tassel-root-index',
    templateUrl: './../views/index.html',
    animations: [pageShowAnimation],
    styleUrls: [
        './../styles/root.css',
        './../styles/index.css',
        './../styles/card.css'
    ]
})
export class IndexComponent extends TasselNavigationBase implements OnInit, OnDestroy, AfterViewInit {

    @HostBinding('@routeAnimation') routeAnimation = true;
    @HostBinding('style.display') display = 'block';

    @ViewChild('indexDiv') private indexDiv: ElementRef;
    @ViewChild('col01') private col01: ElementRef;
    @ViewChild('col02') private col02: ElementRef;
    @ViewChild('col03') private col03: ElementRef;
    @ViewChild('col04') private col04: ElementRef;
    private get column01() { return (this.col01 || { nativeElement: undefined }).nativeElement; }
    private get column02() { return (this.col02 || { nativeElement: undefined }).nativeElement; }
    private get column03() { return (this.col03 || { nativeElement: undefined }).nativeElement; }
    private get column04() { return (this.col04 || { nativeElement: undefined }).nativeElement; }
    private get columns(): [number, number][] {
        return [
            [0, (this.column01 || { clientHeight: 0 }).clientHeight],
            [1, (this.column02 || { clientHeight: 0 }).clientHeight],
            [2, (this.column03 || { clientHeight: 0 }).clientHeight],
            [3, (this.column04 || { clientHeight: 0 }).clientHeight]
        ];
    }

    private shouldRecheck = false;
    private shouldExistLoop = false;

    private _posts: IPost[] = [];
    public get Posts() { return this._posts; }

    private _bindings: IPost[][] = [[], [], [], []];
    public get Bindings() { return this._bindings; }

    private _adaptor: IAdaptor = { Col: 4 };
    public get Adaptor() { return this._adaptor; }

    constructor(
        protected identity: IdentityService,
        protected router: Router) { super(identity, router); }

    ngOnInit(): void {
        this._posts = this.postsProvide();
        this.reselectHeights(4, undefined, true);
    }

    ngOnDestroy(): void {
        this.shouldExistLoop = true;
    }

    private postsProvide = () => {
        return [
            { Cover: 'https://tse1-mm.cn.bing.net/th?id=OIP.C-XsFDZ4CpgjHkNFkqXQDAEsC7&p=0&pid=1.1', Title: '我是一只猫', Summary: '中文测试', Like: 254 },
            { Cover: 'http://p3.wmpic.me/article/2016/07/25/1469459240_PzFfSySK.jpg', Title: 'Europe Street beat', Like: 21, Stamp: 'XXXX-XX-XX' },
            { Title: '什么图片都没有', Summary: '别做梦了。', Like: 213, Stamp: 'XXXX-XX-XX' },
            { Cover: 'https://os.alipayobjects.com/rmsportal/QBnOOoLaAfKPirc.png', Title: 'Europe Street beat', Summary: 'www.instagram.com', Like: 86 },
            { Cover: 'http://i5.qhimg.com/t019c2a1cad4940cf50.jpg', Title: 'Europe Street beat', Summary: 'www.instagram.com', Like: 123 },
            { Cover: 'http://a0.att.hudong.com/70/82/01300000185479121382825220187.jpg', Title: 'Europe Street beat', Summary: 'www.instagram.com', Like: 34 },
            { Cover: 'http://free-photos-ls02.gatag.net/images/lgf01a201401230500.jpg', Title: 'Europe Street beat', Like: 23, Stamp: 'XXXX-XX-XX' },
            { Cover: 'http://pic.bizhi360.com/bpic/46/5046.jpg', Title: 'Europe Street beat', Summary: 'www.instagram.com', Like: 34, Stamp: 'XXXX-XX-XX' },
            { Cover: 'http://a4.att.hudong.com/03/27/01300000066957120529279410702.jpg', Title: 'Europe Street beat', Summary: 'www.instagram.com', Like: 341 },
            { Title: 'No Picture Test', Summary: 'Sorry, there is no picture for showing, if you want see more , close the browser and get out of home.', Like: 456 },
            { Cover: 'http://pic.7y7.com/Uploads/Former/20148/2014083037415845_0_0_water.jpg', Title: 'Something Wrong', Summary: '......', Like: 34524 },
            { Cover: 'http://uploadfile.deskcity.org/2015/0907/20150907025557427.jpg', Title: 'Europe Street beat', Summary: 'www.instagram.com', Like: 3 },
        ];
    }

    ngAfterViewInit(): void {
        this.WaitAndDo(this.rebuildView, 50);
        this.prepareScroll();
    }

    private prepareScroll = () => {
        const root = this.indexDiv.nativeElement as HTMLDivElement;
        const f_parent = root.parentElement.parentElement.parentElement;
        const that = this;
        const onScroll = function () {
            const add_height = this.scrollTop + this.clientHeight;
            if (this.scrollHeight - add_height < 100) {
                f_parent.onscroll = null;
                setTimeout(() => {
                    that.reselectHeights(that._adaptor.Col, that.postsProvide());
                    that.reselectCheck(that._adaptor.Col);
                    f_parent.onscroll = onScroll;
                }, 500);
            }
        };
        f_parent.onscroll = onScroll;
    }

    private rebuildView = async () => {
        if (this.shouldExistLoop) { return; }
{'fraction_non_alphanumeric': 0.1548840218094446, 'fraction_numerical': 0.05045744385916274, 'mean_word_length': 2.8119056005635787, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 4, 'lorem ipsum': 0, 'www.': 12, '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': '5527973', 'n_tokens_mistral': 3760, 'n_tokens_neox': 3400, 'n_words': 759}