delete<T extends Object?> method
Deletes the instance from _instancesByKey
but keep the _builder
function.
Returns true
when the instance has been deleted.
Implementation
bool delete<T extends Object?>([String? id, Object? ref]) {
final instanceKey = ReactterInstance.generateKey<T?>(id);
var reactterInstance = _instancesByKey[instanceKey];
if (reactterInstance == null || reactterInstance.instance == null) {
reactterInstance = ReactterInstance<T>(id);
Reactter.log(
'Instance "$reactterInstance" already deleted.',
isError: true,
);
return false;
}
if (ref != null) {
reactterInstance.refs.remove(ref.hashCode);
}
if (reactterInstance.refs.isNotEmpty) {
return false;
}
_removeInstance<T>(reactterInstance);
Reactter.dispose(reactterInstance);
return true;
}