Composables
PulseApp
kotlin
@Composable
fun <Broadcast : PulseBroadcast> PulseApp(
container: PulseContainer<Broadcast>,
content: @Composable (
onRefresh: () -> Unit,
onBroadcast: (Broadcast) -> Unit,
) -> Unit = { _, _ -> },
)Wraps a PulseContainer and provides onRefresh and onBroadcast callbacks to the content block. All PulseContent composables placed inside PulseApp automatically respond to container.refresh().
Parameters
| Parameter | Type | Description |
|---|---|---|
container | PulseContainer<Broadcast> | The container to observe |
content | @Composable (onRefresh, onBroadcast) -> Unit | Content block receiving the two callbacks |
Example
kotlin
PulseApp(container = appContainer) { onRefresh, onBroadcast ->
Column {
Button(onClick = { onBroadcast(AppBroadcast.Sync) }) {
Text("Sync All")
}
Button(onClick = { onRefresh() }) {
Text("Refresh View")
}
MyContent(store = myStore)
}
}PulseContent
kotlin
@Composable
fun <State : PulseState, Action : PulseAction, Event : PulseEvent, Broadcast : PulseBroadcast>
PulseContent(
store: PulseStore<State, Action, Event, Broadcast>,
onEvent: (Event) -> Unit = {},
content: @Composable (State, (Action) -> Unit) -> Unit = { _, _ -> },
)Observes a PulseStore and provides state and an action dispatcher to the content block. Automatically cancels the Store when removed from the composition.
Parameters
| Parameter | Type | Description |
|---|---|---|
store | PulseStore<State, Action, Event, Broadcast> | The Store to observe |
onEvent | (Event) -> Unit | Called for each one-time side effect emitted by the Store |
content | @Composable (State, (Action) -> Unit) -> Unit | Renders the current state; receives a dispatcher to send actions |
Lifecycle behavior
LaunchedEffect(store)startsonSetup()and begins collectingeventDisposableEffect(store)callsstore.cancel()when the composable leaves the composition- When inside
PulseApp, the composable is wrapped inkey(containerKey)and re-creates onrefresh()
Example
kotlin
PulseContent(
store = counterStore,
onEvent = { event ->
when (event) {
is CounterEvent.ShowMessage ->
scope.launch { snackbarHostState.showSnackbar(event.message) }
}
},
) { state, onAction ->
Column {
Text("Count: ${state.count}")
Button(onClick = { onAction(CounterAction.Increment) }) {
Text("+")
}
}
}