<commit_before>import { Injectable } from '@angular/core';
import { Observable, BehaviorSubject } from 'rxjs';
import { map } from 'rxjs/operators';
import { HttpClient } from '@angular/common/http';
import { IgxGridHierarchicalPipe } from 'projects/igniteui-angular/src/lib/grids/hierarchical-grid/hierarchical-grid.pipes';
import { IgxHierarchicalGridAPIService, IgxHierarchicalGridComponent } from 'igniteui-angular';

@Injectable()
export class HierarchicalRemoteService {

    public remotePagingData: BehaviorSubject<any[]>;
    public cachedData = [];
    requestStartIndex = 0;
    totalCount: number;
    remoteData: Observable<any[]>;
    _remoteData: BehaviorSubject<any[]>;
    url = `https://services.odata.org/V4/Northwind/Northwind.svc/Products`;
    urlBuilder;

    constructor(private http: HttpClient, private hierarchyPipe: IgxGridHierarchicalPipe) {
        this._remoteData = new BehaviorSubject([]);
        this.remoteData = this._remoteData.asObservable();
    }


    nullData() {
        this._remoteData.next(null);
    }

    undefinedData() {
        this._remoteData.next(undefined);
    }

    public getDataFromCache(data: any) {
        const startIndex = data.startIndex;
        const endIndex = (data.chunkSize || 11) + startIndex;
        const dataResult = this.cachedData.slice(startIndex, endIndex);
        while(dataResult.length < data.chunkSize) {
            dataResult.push({emptyRec: true});
        }
        return dataResult;
        this._remoteData.next(dataResult);
        return dataResult;
    }

    private _updateCachedData (data: any, startIndex: number, lastChunk: boolean) {
        for (let i = 0; i < data.length; i++) {
            this.cachedData[i + startIndex] = data[i];
        }
        if (lastChunk) {
            this.cachedData.splice(startIndex + data.length);
        }
    }

    getData(virtualizationState: any, grid: IgxHierarchicalGridComponent, cb?: (any) => void) {
        return this.http.get(this.buildUrl(virtualizationState, grid)).pipe(
            map(response => response),
        )
        .subscribe(d => {
                const result = d['value'];
                this.totalCount = d['@odata.count'];
                if (this.cachedData.length === 0) {
                    this.cachedData = new Array<any>(this.totalCount * 2).fill({emptyRec: true});
                }<commit_msg>chore(*): Append empty records in beginning.<commit_after>import { Injectable } from '@angular/core';
import { Observable, BehaviorSubject } from 'rxjs';
import { map } from 'rxjs/operators';
import { HttpClient } from '@angular/common/http';
import { IgxGridHierarchicalPipe } from 'projects/igniteui-angular/src/lib/grids/hierarchical-grid/hierarchical-grid.pipes';
import { IgxHierarchicalGridAPIService, IgxHierarchicalGridComponent } from 'igniteui-angular';

@Injectable()
export class HierarchicalRemoteService {

    public remotePagingData: BehaviorSubject<any[]>;
    public cachedData = [];
    requestStartIndex = 0;
    totalCount: number;
    remoteData: Observable<any[]>;
    _remoteData: BehaviorSubject<any[]>;
    url = `https://services.odata.org/V4/Northwind/Northwind.svc/Products`;
    urlBuilder;

    constructor(private http: HttpClient, private hierarchyPipe: IgxGridHierarchicalPipe) {
        this._remoteData = new BehaviorSubject([]);
        this.remoteData = this._remoteData.asObservable();
    }


    nullData() {
        this._remoteData.next(null);
    }

    undefinedData() {
        this._remoteData.next(undefined);
    }

    public getDataFromCache(data: any) {
        const startIndex = data.startIndex;
        const endIndex = (data.chunkSize || 11) + startIndex;
        const dataResult = this.cachedData.slice(startIndex, endIndex);
        while(dataResult.length < data.chunkSize) {
            dataResult.unshift({emptyRec: true});
        }
        this._remoteData.next(dataResult);
        return dataResult;
    }

    private _updateCachedData (data: any, startIndex: number, lastChunk: boolean) {
        for (let i = 0; i < data.length; i++) {
            this.cachedData[i + startIndex] = data[i];
        }
        if (lastChunk) {
            this.cachedData.splice(startIndex + data.length);
        }
    }

    getData(virtualizationState: any, grid: IgxHierarchicalGridComponent, cb?: (any) => void) {
        return this.http.get(this.buildUrl(virtualizationState, grid)).pipe(
            map(response => response),
        )
        .subscribe(d => {
                const result = d['value'];
                this.totalCount = d['@odata.count'];
                if (this.cachedData.length === 0) {
                    this.cachedData = new Array<any>(this.totalCount * 2).fill({emptyRec: true});
                }
{'fraction_non_alphanumeric': 0.12345160613058996, 'fraction_numerical': 0.002939323955490237, 'mean_word_length': 2.8637469586374698, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, 'https://': 2, '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': '985487', 'n_tokens_mistral': 1450, 'n_tokens_neox': 1389, 'n_words': 269}