<commit_before>import { Directive, ElementRef, Input, OnInit, OnDestroy } from '@angular/core';
import { Observable } from "rxjs/Observable";

const dirtyDuration = 150; //Leave ids marked dirty for this many ms to ensure that they get updated after render
const dirtyUpdateInterval = 50; //only actually update dirty rows every interval

@Directive({ selector: '[matchMaxHeight]' })
export class MatchMaxHeightDirective implements OnInit, OnDestroy {
	@Input('matchMaxHeight') matchId: string;
	protected actualHeight: string; //actual css "height" attribute value

	private static idMap: {[id: string]: {maxHeight: number, directives: MatchMaxHeightDirective[]}} = {};
	private static dirtyMap = new Map<string,number>(); //id: refresh time remaining
	private static dirtyWait = false;

	constructor(protected el: ElementRef) {
		this.actualHeight = "";
	}

	ngOnInit() {
		if(!MatchMaxHeightDirective.idMap[this.matchId]) {
			MatchMaxHeightDirective.idMap[this.matchId] = {maxHeight: 0, directives: []};
		}
		MatchMaxHeightDirective.idMap[this.matchId].directives.push(this);
		MatchMaxHeightDirective.markDirty(this.matchId);
	}

	ngOnDestroy() {
		MatchMaxHeightDirective.idMap[this.matchId].directives.filter(v => v !== this);
		if(MatchMaxHeightDirective.idMap[this.matchId].directives.length === 0) {
			delete MatchMaxHeightDirective.idMap[this.matchId];
			MatchMaxHeightDirective.dirtyMap.delete(this.matchId);
		}
	}

	public static markDirty(id: string): void {
		if(MatchMaxHeightDirective.dirtyMap.size === 0) {
			let dirtyUpdateSubscription = Observable.interval(dirtyUpdateInterval).subscribe(() => {
				if(MatchMaxHeightDirective.dirtyMap.size === 0) {
					dirtyUpdateSubscription.unsubscribe();
					return;
				}

				MatchMaxHeightDirective.dirtyMap.forEach((time, id) => {
					MatchMaxHeightDirective.update(id);
					let newTime = time - dirtyUpdateInterval;
					if(newTime <= 0) {
						MatchMaxHeightDirective.dirtyMap.delete(id);
					} else {<commit_msg>Fixed MatchMaxHeight failing when id is changed<commit_after>import { Directive, ElementRef, Input, OnInit, OnChanges, OnDestroy } from '@angular/core';
import { Observable } from "rxjs/Observable";

const dirtyDuration = 150; //Leave ids marked dirty for this many ms to ensure that they get updated after render
const dirtyUpdateInterval = 50; //only actually update dirty rows every interval

@Directive({ selector: '[matchMaxHeight]' })
export class MatchMaxHeightDirective implements OnInit, OnChanges, OnDestroy {
	@Input('matchMaxHeight') matchId: string;
	protected actualHeight: string; //actual css "height" attribute value

	private static idMap: {[id: string]: {maxHeight: number, directives: MatchMaxHeightDirective[]}} = {};
	private static dirtyMap = new Map<string,number>(); //id: refresh time remaining
	private static dirtyWait = false;

	constructor(protected el: ElementRef) {
		this.actualHeight = "";
	}

	ngOnInit() {
		//this.registerDirective(this.matchId);
	}

	ngOnChanges(changes: any) {
		this.unregisterDirective(changes.matchId.previousValue);
		this.registerDirective(changes.matchId.currentValue);
	}

	ngOnDestroy() {
		this.unregisterDirective(this.matchId);
	}

	protected registerDirective(id: string) {
		if(!MatchMaxHeightDirective.idMap[id]) {
			MatchMaxHeightDirective.idMap[id] = {maxHeight: 0, directives: []};
		}
		MatchMaxHeightDirective.idMap[id].directives.push(this);
		MatchMaxHeightDirective.markDirty(id);
	}

	protected unregisterDirective(id: string) {
		if(!MatchMaxHeightDirective.idMap[id]) {
			return;
		}
		MatchMaxHeightDirective.idMap[id].directives = MatchMaxHeightDirective.idMap[id].directives.filter(v => v !== this);
		if(MatchMaxHeightDirective.idMap[id].directives.length === 0) {
			delete MatchMaxHeightDirective.idMap[id];
			MatchMaxHeightDirective.dirtyMap.delete(id);
		}
	}

	public static markDirty(id: string): void {
		if(MatchMaxHeightDirective.dirtyMap.size === 0) {
			let dirtyUpdateSubscription = Observable.interval(dirtyUpdateInterval).subscribe(() => {
				if(MatchMaxHeightDirective.dirtyMap.size === 0) {
					dirtyUpdateSubscription.unsubscribe();
					return;
				}

				MatchMaxHeightDirective.dirtyMap.forEach((time, id) => {
					MatchMaxHeightDirective.update(id);
					let newTime = time - dirtyUpdateInterval;
					if(newTime <= 0) {
						MatchMaxHeightDirective.dirtyMap.delete(id);
					} else {
{'fraction_non_alphanumeric': 0.12063854047890536, 'fraction_numerical': 0.004561003420752566, 'mean_word_length': 5.247863247863248, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '6607130', 'n_tokens_mistral': 1455, 'n_tokens_neox': 1301, 'n_words': 281}