<commit_before>package tink.reactive;

/**
 * ...
 * @author back2dos
 */

interface Source<T> {
	var value(get_value, null):T;
	function unwatch(handler:Void->Void):Void;
	function watch(handler:Void->Void):Void;
}
interface Editable<T> implements Source<T> {
	var value(get_value, set_value):T;
}

/*
TODO: consider using this instead, after some profiling 
typedef Source<T> = {
	var value(get_value, null):T;
	function unwatch(handler:Void->Void):Void;
	function watch(handler:Void->Void):Void;
}
typedef Editable<T> = {
	var value(get_value, set_value):T;<commit_msg>Plain vanilla source. Might come in handy.<commit_after>package tink.reactive;
import tink.collections.maps.FunctionMap;
import tink.lang.Cls;

/**
 * ...
 * @author back2dos
 */

interface Source<T> {
	var value(get_value, null):T;
	function unwatch(handler:Void->Void):Void;
	function watch(handler:Void->Void):Void;
}
interface Editable<T> implements Source<T> {
	var value(get_value, set_value):T;
}
class PlainSource<T> implements Source<T>, implements Editable<T>, implements Cls {
	var handlers = new FunctionMap<Void->Void, Void->Void>();	
	public function unwatch(handler:Void->Void):Void {
		handlers.remove(handler);
	}
	public function watch(handler:Void->Void):Void {
		handlers.set(handler, handler);
	}		
	
	public var value(get_value, set_value):T = _;
	function get_value() return value
	function set_value(param) {
		value = param;
		for (h in handlers) h();
		return param;
	}
	
}
/*
TODO: consider using this instead, after some profiling 
typedef Source<T> = {
	var value(get_value, null):T;
	function unwatch(handler:Void->Void):Void;
	function watch(handler:Void->Void):Void;
}
typedef Editable<T> = {
	var value(get_value, set_value):T;
{'fraction_non_alphanumeric': 0.14376443418013857, 'fraction_numerical': 0.0011547344110854503, 'mean_word_length': 5.515037593984962, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 29, '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': '6690418', 'n_tokens_mistral': 617, 'n_tokens_neox': 620, 'n_words': 134}