delete<T extends Object?> method
Deletes the instance from the store if it has been removed from all references and meets the conditions of instance type.
Returns true
when the instance has been deleted.
Implementation
bool delete<T extends Object?>([String? id, Object? ref]) {
final reactterInstance = _getReactterInstance<T>(id);
if (reactterInstance?.instance == null) {
final reactterInstance = ReactterInstance<T>(id);
Reactter.log('The "$reactterInstance" instance already deleted.');
return false;
}
if (ref != null) {
reactterInstance!.refs.remove(ref.hashCode);
}
if (reactterInstance!.refs.isNotEmpty) {
return false;
}
switch (reactterInstance.mode) {
case InstanceManageMode.builder:
destroy<T>(id: id);
return true;
case InstanceManageMode.factory:
_removeInstance<T>(reactterInstance);
Reactter.log(
'The "$reactterInstance" builder has been retained '
'because it\'s `${InstanceManageMode.factory}`.',
);
return true;
case InstanceManageMode.singleton:
Reactter.log(
'The "$reactterInstance" instance has been retained '
'because it\'s `${InstanceManageMode.singleton}`.',
);
}
return false;
}