data static method
Access to the data container, retrieve WireData object when value is null and set when is not
WireData is a data container to changes of which anyone can subscribe/unsubscribe.
It's associated with string key.
WireData can't be null and Wire.data(key) will always return WireData instance.
Initial value will be null and special property of WireData isSet equal to false until any value is set
If value is null then delete method of WireData will be called, object will be removed from system
To protect WireData from being set from unappropriated places the WireDataLockToken token introduced.
When only specific object want have rights to write/change value of WireData it can create WireDataLockToken object
and pass it to Wire.data method as option parameter token
to validate the assign action.
WireData API:
WireData subscribe(WireDataListener listener)
WireData unsubscribe([WireDataListener listener])
void setValue(T input, { DataModificationToken token })
void refresh()
void remove()
Returns WireData
Implementation
static WireData data(String key, {dynamic value, WireDataGetter? getter}) {
final WireData wireData = _DATA_CONTAINER_LAYER.has(key)
? _DATA_CONTAINER_LAYER.get(key)
: _DATA_CONTAINER_LAYER.create(key, _MIDDLEWARE_LAYER.onReset);
if (getter != null) {
wireData.getter = getter;
wireData.lock(WireDataLockToken());
}
// print('> Wire -> WireData - data key = ${key}, value = ${value}, getter = ${getter}');
if (value != null) {
if (wireData.isGetter) throw Exception(ERROR__VALUE_IS_NOT_ALLOWED_TOGETHER_WITH_GETTER);
final prevValue = wireData.isSet ? wireData.value : null;
final nextValue = (value is WireValueFunction) ? value(prevValue) : value;
_MIDDLEWARE_LAYER.onData(key, prevValue, nextValue);
wireData.value = nextValue;
}
return wireData;
}