Skip to content

Commit

Permalink
Updated showcase example in README file
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris committed Apr 14, 2023
1 parent 00fe6ed commit 9600b52
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,19 @@ fun counterReducer(state: Int?, change: CounterChange): Int {
}
}

fun testCounter() {
val viewModel = ViewModel.create(reducer = ::counterReducer).apply { bind() }
@Composable
fun Counter() {
val viewModel = remember { ViewModel.create(reducer = ::counterReducer) }

viewModel.subscribe { state ->
println(state)
}
val state by viewModel.stateChanges()

viewModel.dispatch(CounterChange.INCREMENT) // 1
viewModel.dispatch(CounterChange.INCREMENT) // 2
viewModel.dispatch(CounterChange.DECREMENT) // 1
Text("Count = $state")

viewModel.unbind()
LaunchedEffect(Unit) {
viewModel.dispatch(CounterChange.INCREMENT) // 1
viewModel.dispatch(CounterChange.INCREMENT) // 2
viewModel.dispatch(CounterChange.DECREMENT) // 1
}
}
```

Expand Down

0 comments on commit 9600b52

Please sign in to comment.