<commit_before>import _IDOM = require("incremental-dom");

declare let require:Function

let inst_watched:{[key:string]:{detached?:Function}}={};
let uid_generated:number = new Date().getTime()+1298;

_IDOM.notifications.nodesDeleted = function(nodes:any) {
  //console.log(inst_watched);
  //console.log(inst_watched);
  nodes.forEach((node:any)=>{
  	//console.log(node);
  	if(node.id && inst_watched[node.id] && inst_watched[node.id].detached){
  		inst_watched[node.id].detached();
  	} 
  	if(node.id && inst_watched[node.id]){
  		inst_watched[node.id] = null;
  		delete inst_watched[node.id];
  	};  
  });
};

export class FerrugemJSFactory{
	private _$content$_:Function;
	private _$target$_:string;
	private _$loaded$_:boolean;
	private _$key$_:string;
	private _$style_name$_:string;
	private _$tag_name$_:string;
	private render:Function;
	private attached:Function;
	private detached:Function;
	/*
	 Factory of class
	*/
	public build(config:{
		classFactory:any
		,hostVars:{}
		,staticVars:{}
		,tagName:string
		,target:string
	}):FerrugemJSFactory{

		let _key = "";
		//find any key
		if(config.hostVars && config.hostVars["key:id"]){
			_key = config.hostVars["key:id"];
			delete config.hostVars["key:id"];
		}else if(config.staticVars && config.staticVars["key:id"]){
			_key = config.staticVars["key:id"];
			delete config.staticVars["key:id"];
		}

		//append methods refresh and content to prototype
		if(!config.classFactory.prototype.refresh){
			config.classFactory.prototype.refresh = FerrugemJSFactory.prototype.refresh;
		}

		//append methods refresh and content to prototype
		if(!config.classFactory.prototype.content){
			config.classFactory.prototype.content = FerrugemJSFactory.prototype.content;
		}

		//lookup for old inst
		if(_key && inst_watched[_key]){
			//console.log('1',inst_watched[_key]);
			return <any>inst_watched[_key];
		}
		//save the new inst in watched insts
		if(_key && !inst_watched[_key]){
			inst_watched[_key] = new config.classFactory();
			inst_watched[_key]["_$target$_"] = config.target;
			inst_watched[_key]["_$key$_"] = _key;
			inst_watched[_key]["_$tagName$_"] = config.tagName;
			this.changeAttrs.call(inst_watched[_key],config.hostVars);
			this.changeAttrs.call(inst_watched[_key],config.staticVars);

			//console.log('2',inst_watched[_key]);
			return <any>inst_watched[_key];
		}
		//only a temp class
		let _inst_ = new config.classFactory();
		_inst_["_$target$_"] = config.target;
		_inst_["_$tagName$_"] = config.tagName;
		this.changeAttrs.call(_inst_,config.hostVars);
		this.changeAttrs.call(_inst_,config.staticVars);
		//console.log('3',_inst_);
		return _inst_;
	}

	public content($content$?:Function):FerrugemJSFactory{
		if($content$){<commit_msg>update dinamics vars from view for old instances<commit_after>import _IDOM = require("incremental-dom");

declare let require:Function

let inst_watched:{[key:string]:{detached?:Function}}={};
let uid_generated:number = new Date().getTime()+1298;

_IDOM.notifications.nodesDeleted = function(nodes:any) {
  nodes.forEach((node:any)=>{
  	if(node.id && inst_watched[node.id] && inst_watched[node.id].detached){
  		inst_watched[node.id].detached();
  	} 
  	if(node.id && inst_watched[node.id]){
  		inst_watched[node.id] = null;
  		delete inst_watched[node.id];
  	};  
  });
};

export class FerrugemJSFactory{
	private _$content$_:Function;
	private _$target$_:string;
	private _$loaded$_:boolean;
	private _$key$_:string;
	private _$style_name$_:string;
	private _$tag_name$_:string;
	private render:Function;
	private attached:Function;
	private detached:Function;
	/*
	 Factory of class
	*/
	public build(config:{
		classFactory:any
		,hostVars:{}
		,staticVars:{}
		,tagName:string
		,target:string
	}):FerrugemJSFactory{

		let _key = "";
		//find any key
		if(config.hostVars && config.hostVars["key:id"]){
			_key = config.hostVars["key:id"];
			delete config.hostVars["key:id"];
		}else if(config.staticVars && config.staticVars["key:id"]){
			_key = config.staticVars["key:id"];
			delete config.staticVars["key:id"];
		}

		//append methods refresh and content to prototype
		if(!config.classFactory.prototype.refresh){
			config.classFactory.prototype.refresh = FerrugemJSFactory.prototype.refresh;
		}

		//append methods refresh and content to prototype
		if(!config.classFactory.prototype.content){
			config.classFactory.prototype.content = FerrugemJSFactory.prototype.content;
		}

		//lookup for old inst
		if(_key && inst_watched[_key]){
			//console.log('1',inst_watched[_key]);
			//update dinamics vars from view
			this.changeAttrs.call(inst_watched[_key],config.hostVars);
			return <any>inst_watched[_key];
		}
		//save the new inst in watched insts
		if(_key && !inst_watched[_key]){
			inst_watched[_key] = new config.classFactory();
			inst_watched[_key]["_$target$_"] = config.target;
			inst_watched[_key]["_$key$_"] = _key;
			inst_watched[_key]["_$tagName$_"] = config.tagName;
			this.changeAttrs.call(inst_watched[_key],config.hostVars);
			this.changeAttrs.call(inst_watched[_key],config.staticVars);

			//console.log('2',inst_watched[_key]);
			return <any>inst_watched[_key];
		}
		//only a temp class instance
		let _inst_ = new config.classFactory();
		_inst_["_$target$_"] = config.target;
		_inst_["_$tagName$_"] = config.tagName;
		this.changeAttrs.call(_inst_,config.hostVars);
		this.changeAttrs.call(_inst_,config.staticVars);
		//console.log('3',_inst_);
		return _inst_;
	}

	public content($content$?:Function):FerrugemJSFactory{
		if($content$){
{'fraction_non_alphanumeric': 0.15763813651137595, 'fraction_numerical': 0.002527988443481401, 'mean_word_length': 5.106945975744211, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '5603919', 'n_tokens_mistral': 2093, 'n_tokens_neox': 1953, 'n_words': 310}