<commit_before>/**
 * @file Component: Busy
 * @author yumao<<EMAIL>>
 */

import {
    Component,
    DoCheck,
    Input,
    trigger,
    state,
    style,
    transition,
    animate
} from '@angular/core';
import {DomSanitizer, SafeHtml} from '@angular/platform-browser';

import {PromiseTrackerService} from './promise-tracker.service';

const inactiveStyle = style({
    opacity: 0,
    transform: 'translateY(-40px)'
});
const timing = '.3s ease';

@Component({
    selector: 'ng-busy',
    template: `
        <div *ngIf="isActive()" [class]="wrapperClass" [innerHTML]="safeTemplate" @flyInOut>
        </div>
    `,
    animations: [
        trigger('flyInOut', [
            transition('void => *', [
                inactiveStyle,
                animate(timing)
            ]),
            transition('* => void', [
                animate(timing, inactiveStyle)
            ])
        ])
    ]
})
export class BusyComponent implements DoCheck {
    message: string;
    wrapperClass: string;
    template: string;
    safeTemplate: SafeHtml;

    constructor(
        private tracker: PromiseTrackerService,
        private sanitizer: DomSanitizer
    ) {
    }

    ngDoCheck() {
        if (!this.template) {
            return;
        }

        this.safeTemplate = this.sanitizer.bypassSecurityTrustHtml(
            // XXX: fake dynamic template
            this.template.replace('{{message}}', this.message)
        );
    }

    isActive() {
        return this.tracker.isActive();
    }
}
<commit_msg>optimize ngDoCheck<commit_after>/**
 * @file Component: Busy
 * @author yumao<<EMAIL>>
 */

import {
    Component,
    DoCheck,
    trigger,
    state,
    style,
    transition,
    animate
} from '@angular/core';
import {DomSanitizer, SafeHtml} from '@angular/platform-browser';

import {PromiseTrackerService} from './promise-tracker.service';

const inactiveStyle = style({
    opacity: 0,
    transform: 'translateY(-40px)'
});
const timing = '.3s ease';

@Component({
    selector: 'ng-busy',
    template: `
        <div *ngIf="isActive()" [class]="wrapperClass" [innerHTML]="safeTemplate" @flyInOut>
        </div>
    `,
    animations: [
        trigger('flyInOut', [
            transition('void => *', [
                inactiveStyle,
                animate(timing)
            ]),
            transition('* => void', [
                animate(timing, inactiveStyle)
            ])
        ])
    ]
})
export class BusyComponent implements DoCheck {
    message: string;
    prevMessage: string;
    wrapperClass: string;
    template: string;
    safeTemplate: SafeHtml;

    constructor(
        private tracker: PromiseTrackerService,
        private sanitizer: DomSanitizer
    ) {
    }

    ngDoCheck() {
        if (!this.template || this.message === this.prevMessage) {
            return;
        }

        this.safeTemplate = this.sanitizer.bypassSecurityTrustHtml(
            // XXX: fake dynamic template
            this.template.replace('{{message}}', this.message)
        );

        this.prevMessage = this.message;
    }

    isActive() {
        return this.tracker.isActive();
    }
}

{'fraction_non_alphanumeric': 0.13104325699745548, 'fraction_numerical': 0.002544529262086514, 'mean_word_length': 2.1608040201005023, 'pattern_counts': {'":': 0, '<': 11, '<?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': '315679', 'n_tokens_mistral': 943, 'n_tokens_neox': 901, 'n_words': 188}