Git Product home page Git Product logo

compose-state-events's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

compose-state-events's Issues

Action for EventEffect or NavigationEffect is called twice per trigger.

Hi. Thank you for this library! Noticed a possible bug where the action for an EventEffect or NavigationEventEffect is called twice when triggered. This happens when the onConsumed parameter is set with a lambda. I think this is a valid way to use the effects, but I'm not sure. Can you let me know your thoughts? Thanks again

val screenState by viewModel.screenState.collectAsStateWithLifecycle()

// The action for this effect is called twice per trigger.
NavigationEventEffect(
    event = screenState.closeEvent,
    onConsumed = { viewModel.onConsumeCloseEvent() }
) {
    navController.popBackStack()
}

// The action for this version is called just once as expected.
NavigationEventEffect(
    event = screenState.closeEvent,
    onConsumed = viewModel::onConsumeCloseEvent
) {
    navController.popBackStack()
}

// View Model
private val _screenState = MutableStateFlow(initialState)
val screenState = _screenState.asStateFlow()

...

fun onCloseClick() {
    _screenState.update { it.copy(closeEvent = triggered) }
}

fun onConsumeCloseEvent() {
    _screenState.update { it.copy(closeEvent = consumed) }
}

A possible fix for this is to remove the onConsumed parameter from the keys on the LaunchedEffect within NavigationEventEffect and EventEffect.

How is the library used together with paging3?

I have a Room DAO that has the following query. My ViewModel then defines the Pager instance I use inside my ViewModel as shown below:

/// DAO
@Query("SELECT * FROM <table> ORDER BY createdAt DESC")
fun getAllPaged(): PagingSource<Int, Model>

/// ViewModel
class MyViewModel: ViewModel() {
    val allItems = Pager(PagingConfig(pageSize = 10)) {
        myDao.getAllPaged()
    }.flow.cachedIn(viewModelScope)
}

/// UI
@Composable
fun MyContent(viewModel: MyViewModel = hiltViewModel()) {
    val items = viewModel.allItems.collectAsLazyPagingItems()
}

How do I keep the Pager lazy when adding it to the ViewState data class? I don't know if this is possible and by checking online I don't think it is.

Mark StateEvent(WithContent) as Stable/Immutable

Hi,

I'm wondering what your thoughts are about marking the StateEvent / StateEventWithContent and its implementation as either Stable or Immutable. I think both are applicable (though Immutable should be more fitting) and would enable the Composables where those types are used to be skippable.

Any thoughts on this?

As reference: Jetpack Compose Stability Explained

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.