uninitialize<T> method

void uninitialize<T>(
  1. StoreToken token,
  2. StoreDisposer<T>? dispose
)

Releases the resources of a recreateable store

Implementation

void uninitialize<T>(StoreToken token, StoreDisposer<T>? dispose) {
  if (_uninitialized.containsKey(token))
    throw Exception("$token hasn't been initialized");
  else if (_disposed.containsKey(token)) {
    throw Exception("$token has already been dispoed or it doesn't exist");
  } else {
    if (!_reusable.containsKey(token))
      throw Exception(
          "$token isn't re-createable. Only stores makred true as recreate can be unninitialize");

    final store = _initialized[token];
    try {
      dispose?.call(store);
    } catch (e, stack) {
      print("Execption occured when disposing the store");
      print(stack);
    }
    _initialized.remove(token);
    _uninitialized[token] = _reusable[token]!;
    _reusable.remove(token);
  }
}