Observable constructor
Observable(})
Implementation
Observable(this.key, dynamic value, {this.scope, OnChangeCallback? listener, this.getter, this.setter, this.lazyEvaluation = false})
{
if (value is String)
{
// bindings?
if (this is! BlobObservable) bindings = Binding.getBindings(value, scope: scope);
if (bindings != null)
{
// replace the "this" operator
if (value.contains("this") && key != null)
{
String id = key!.split(".").first;
// replace "this" with the id in the signature
for(Binding binding in bindings!) {
if (binding.source == "this")
{
var signature = binding.signature.replaceFirst("this",id);
value = (value as String).replaceAll(binding.signature, signature);
}
}
// requery the bindings
bindings = Binding.getBindings(value, scope: scope);
}
// save the signature
signature = value;
}
// eval?
isEval = isEvalSignature(value);
if (_isEval == true)
{
value = getEvalSignature(value);
signature = value;
}
///////////
/* 2-way */
///////////
String t = '@{';
if ((bindings != null) && (bindings!.length == 1) && (value.trim().toLowerCase().startsWith(t)) && (value.trim().toLowerCase().endsWith('}')))
{
twoway = true;
value = (value as String).substring(1);
signature = value;
}
}
///////////////////
/* Set the Value */
///////////////////
if (bindings == null) _value = to(value);
////////////////////////
/* Perform Evaluation */
////////////////////////
if ((isEval) || bindings != null) onObservableChange(null);
//////////////////
/* Add Listener */
//////////////////
if (listener != null) registerListener(listener);
//////////////
/* Register */
//////////////
if (scope != null) scope!.register(this);
////////////
/* Notify */
////////////
notifyListeners();
}