<commit_before>import MultiNodeWidget = require('../../../ui/dom/MultiNodeWidget');
import Promise = require('../../../Promise');
import Proxy = require('../../../data/Proxy');
import View = require('../../../ui/View');
import util = require('../../../util');

function createSetter(property:string):(value:View) => void {
	return function (value:View):void {
		if (this[property] && this[property].get('isAttached')) {
			this.remove(this[property]);
			value.set('model', this[property].get('model'));
			this.add(value);
		}

		this[property] = value;
	};
}

class PromiseWidget<T> extends MultiNodeWidget {
	private _as:string;
	private _fulfilled:View;
	private _pending:View;
	private _pendingAs:string;
	private _value:Promise<T>;
	private _rejected:View;
	private _rejectedAs:string;

	get:PromiseWidget.Getters<T>;
	on:PromiseWidget.Events;
	set:PromiseWidget.Setters<T>;

	constructor(kwArgs?:HashMap<any>) {
		util.deferSetters(this, [ 'value' ], '_render');
		super(kwArgs);
	}

	_initialize():void {
		super._initialize();

		this._as = 'value';
		this._pendingAs = 'progress';
		this._rejectedAs = 'error';
	}

	_valueGetter():Promise<T> {
		return this._value;
	}
	_valueSetter(value:T):void;
	_valueSetter(value:Promise<T>):void;
	_valueSetter(value:any):void {
		this._value = Promise.resolve<T>(value);
		var self = this;

		function setModel(view:View, as:string, value:any):void {
			var kwArgs:HashMap<any> = {
				app: self._app,
				model: self.get('model')
			};
			kwArgs[as] = value;
			var proxy = new Proxy(kwArgs);

			var oldModel:{ destroy:() => void } = <any>view.get('model');
			view.set('model', proxy);

			if (oldModel && oldModel.destroy) {
				oldModel.destroy();
			}
		}

		function attach(view:View):void {
			self._lastNode.parentNode.insertBefore(view.detach(), self._lastNode);
			view.set({
				isAttached: self.get('isAttached'),
				parent: self
			});<commit_msg>Blind fix for Promise widget<commit_after>import MultiNodeWidget = require('../../../ui/dom/MultiNodeWidget');
import Promise = require('../../../Promise');
import Proxy = require('../../../data/Proxy');
import View = require('../../../ui/View');
import util = require('../../../util');

function createSetter(property:string):(value:View) => void {
	return function (value:View):void {
		if (this[property] && this[property].get('isAttached')) {
			this.remove(this[property]);
			value.set('model', this[property].get('model'));
			this.add(value);
		}

		this[property] = value;
	};
}

class PromiseWidget<T> extends MultiNodeWidget {
	static inheritsModel:boolean = true;

	private _as:string;
	private _fulfilled:View;
	private _pending:View;
	private _pendingAs:string;
	private _value:Promise<T>;
	private _rejected:View;
	private _rejectedAs:string;

	get:PromiseWidget.Getters<T>;
	on:PromiseWidget.Events;
	set:PromiseWidget.Setters<T>;

	constructor(kwArgs?:HashMap<any>) {
		util.deferSetters(this, [ 'value' ], '_render');
		super(kwArgs);
	}

	_initialize():void {
		super._initialize();

		this._as = 'value';
		this._pendingAs = 'progress';
		this._rejectedAs = 'error';
	}

	_valueGetter():Promise<T> {
		return this._value;
	}
	_valueSetter(value:T):void;
	_valueSetter(value:Promise<T>):void;
	_valueSetter(value:any):void {
		this._value = Promise.resolve<T>(value);
		var self = this;

		function setModel(view:View, as:string, value:any):void {
			var kwArgs:HashMap<any> = {
				app: self._app,
				target: self.get('model')
			};
			kwArgs[as] = value;
			var proxy = new Proxy(kwArgs);

			var oldModel:{ destroy:() => void } = <any>view.get('model');
			view.set('model', proxy);

			if (oldModel && oldModel.destroy) {
				oldModel.destroy();
			}
		}

		function attach(view:View):void {
			self._lastNode.parentNode.insertBefore(view.detach(), self._lastNode);
			view.set({
				isAttached: self.get('isAttached'),
				parent: self
			});
{'fraction_non_alphanumeric': 0.1848414539829853, 'fraction_numerical': 0.0, 'mean_word_length': 4.3517241379310345, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 27, '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': '1666377', 'n_tokens_mistral': 1442, 'n_tokens_neox': 1304, 'n_words': 229}