<commit_before>import { EventEmitter } from 'angular2/angular2';
import { Http, Response } from 'angular2/http';

import { Animation } from './animation';

let cache: Map<any, any> = new Map();

export class IconStore {
	queue: Map<any, any> = new Map();
	private _http: Http;
	constructor(http: Http) {
		this._http = http;
	}
	get(url: string): any {
		let that: IconStore = this;
		let subject: EventEmitter = new EventEmitter();
		subject = subject.toRx();
		if (cache.has(url)) {
			// Delay the next tick until the subject is returned, otherwise the subscriber will not be notified about the next tick if called before return
			// TODO: make sure that this happens after the promise has been returned
			Animation.rAF(function () {
				subject.next(cache.get(url).cloneNode(true));
			});
		} else {
			let pending: boolean = this.queue.has(url);
			if (!pending) this.queue.set(url, []);
			let subs: any[] = this.queue.get(url);
			if (pending) subs.push(subject);
			else {
				subs.push(subject);
				this._http
					.get(url)
					.map((response) => svg(response))
					.subscribe((element) => {
						cache.set(url, element);
						subs.forEach((sub) => sub.next(element.cloneNode(true)));
						that.queue.delete(url);
					});<commit_msg>chore: use `this` instead of `that` as arrow functions keep the parent scope<commit_after>import { EventEmitter } from 'angular2/angular2';
import { Http, Response } from 'angular2/http';

import { Animation } from './animation';

let cache: Map<any, any> = new Map();

export class IconStore {
	queue: Map<any, any> = new Map();
	private _http: Http;
	constructor(http: Http) {
		this._http = http;
	}
	get(url: string): any {
		let subject: EventEmitter = new EventEmitter();
		subject = subject.toRx();
		if (cache.has(url)) {
			// Delay the next tick until the subject is returned, otherwise the subscriber will not be notified about the next tick if called before return
			// TODO: make sure that this happens after the promise has been returned
			Animation.rAF(function () {
				subject.next(cache.get(url).cloneNode(true));
			});
		} else {
			let pending: boolean = this.queue.has(url);
			if (!pending) this.queue.set(url, []);
			let subs: any[] = this.queue.get(url);
			if (pending) subs.push(subject);
			else {
				subs.push(subject);
				this._http
					.get(url)
					.map((response) => svg(response))
					.subscribe((element) => {
						cache.set(url, element);
						subs.forEach((sub) => sub.next(element.cloneNode(true)));
						this.queue.delete(url);
					});
{'fraction_non_alphanumeric': 0.14651437573847972, 'fraction_numerical': 0.0023631350925561244, 'mean_word_length': 3.5357142857142856, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, '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': '3697657', 'n_tokens_mistral': 924, 'n_tokens_neox': 796, 'n_words': 238}