Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose onCancel() method to cubit/bloc #4352

Open
jkouubb opened this issue Feb 8, 2025 · 0 comments
Open

feat: expose onCancel() method to cubit/bloc #4352

jkouubb opened this issue Feb 8, 2025 · 0 comments

Comments

@jkouubb
Copy link

jkouubb commented Feb 8, 2025

Description

I'm using Cubit as a model that supports auto refresh, like codes below:

`@freezed
class ModelWrapperState with _$ModelWrapperState {
const factory ModelWrapperState.initial() = _ModelInitial;

const factory ModelWrapperState.loaded(T value, int expiredAt) = _ModelLoaded;

const factory ModelWrapperState.expired(T value) = _ModelExpired;

const factory ModelWrapperState.error() = _ModelError;

const ModelWrapperState._();
}`

I have some static instances extending DataCenter, which holds a Map<String, ModelWrapperState>.

In that way, no matter how many places use a story model, as long as model they are using has the same key, they are using the same model.

However, this map is going to be very big, because ModelWrapperCubit can't know whether there is no BlocBuilder using them, so it can't be called close().

Desired Solution
In fact, BlocBase use StreamController to dispatch state. And StreamController.onCancel() is called when there is no active subscriber. So maybe we can expose this callback to Cubit and Bloc level, so that they can know when to release themselves.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant