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

Update stateflow for lifecycle #256

Merged
merged 4 commits into from
Feb 1, 2024
Merged

Conversation

hoangchungk53qx1
Copy link
Contributor

Update lifecycle type safer

@Tlaster
Copy link
Owner

Tlaster commented Feb 1, 2024

Thanks for the PR!
Is it possible to create some test case that will be failed before these changes?

@hoangchungk53qx1
Copy link
Contributor Author

hoangchungk53qx1 commented Feb 1, 2024

Thanks for the PR! Is it possible to create some test case that will be failed before these changes?

Hi @Tlaster ,I don't want to access currentState directly to change the behavior, sometimes it to error

ex:   lifecycleOwner.lifecycle.currentState = (Lifecycle.State.Active) 
        lifecycleOwner.lifecycle.currentState = (Lifecycle.State.Destroyed)
or     lifecycleOwner.lifecycle.currentStateFlow.value = Lifecycle.State.Active // cannot access

and i created currentStateFlow purpose observer state
ex in android implementation

 @Composable
 fun Lifecycle.currentStateAsState(): State<Lifecycle.State> = currentStateFlow.collectAsState()

inspired by https://github.com/arkivanov/Essenty?tab=readme-ov-file#lifecycle

Copy link
Owner

@Tlaster Tlaster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! LGTM!

@Tlaster Tlaster merged commit e914ffb into Tlaster:master Feb 1, 2024
2 checks passed
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

Successfully merging this pull request may close these issues.

2 participants