Skip to content
This repository was archived by the owner on Apr 19, 2022. It is now read-only.

Commit c3d98c3

Browse files
committed
Don't emit duplicate consecutive MviViewStates.
See #31
1 parent 4758fe5 commit c3d98c3

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

app/src/main/java/com/example/android/architecture/blueprints/todoapp/addedittask/AddEditTaskViewModel.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ class AddEditTaskViewModel(
8888
// the previous cached one and the latest Result emitted from the action processor.
8989
// The Scan operator is used here for the caching.
9090
.scan(AddEditTaskViewState.idle(), reducer)
91+
// When a reducer just emits previousState, there's no reason to call render. In fact,
92+
// redrawing the UI in cases like this can cause jank (e.g. messing up snackbar animations
93+
// by showing the same snackbar twice in rapid succession).
94+
.distinctUntilChanged()
9195
// Emit the last one event of the stream on subscription
9296
// Useful when a View rebinds to the ViewModel after rotation.
9397
.replay(1)

app/src/main/java/com/example/android/architecture/blueprints/todoapp/statistics/StatisticsViewModel.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ class StatisticsViewModel(
8484
// the previous cached one and the latest Result emitted from the action processor.
8585
// The Scan operator is used here for the caching.
8686
.scan(StatisticsViewState.idle(), reducer)
87+
// When a reducer just emits previousState, there's no reason to call render. In fact,
88+
// redrawing the UI in cases like this can cause jank (e.g. messing up snackbar animations
89+
// by showing the same snackbar twice in rapid succession).
90+
.distinctUntilChanged()
8791
// Emit the last one event of the stream on subscription.
8892
// Useful when a View rebinds to the ViewModel after rotation.
8993
.replay(1)

app/src/main/java/com/example/android/architecture/blueprints/todoapp/taskdetail/TaskDetailViewModel.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ class TaskDetailViewModel(
8787
// the previous cached one and the latest Result emitted from the action processor.
8888
// The Scan operator is used here for the caching.
8989
.scan(TaskDetailViewState.idle(), reducer)
90+
// When a reducer just emits previousState, there's no reason to call render. In fact,
91+
// redrawing the UI in cases like this can cause jank (e.g. messing up snackbar animations
92+
// by showing the same snackbar twice in rapid succession).
93+
.distinctUntilChanged()
9094
// Emit the last one event of the stream on subscription
9195
// Useful when a View rebinds to the ViewModel after rotation.
9296
.replay(1)

app/src/main/java/com/example/android/architecture/blueprints/todoapp/tasks/TasksViewModel.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ class TasksViewModel(
9292
// the previous cached one and the latest Result emitted from the action processor.
9393
// The Scan operator is used here for the caching.
9494
.scan(TasksViewState.idle(), reducer)
95+
// When a reducer just emits previousState, there's no reason to call render. In fact,
96+
// redrawing the UI in cases like this can cause jank (e.g. messing up snackbar animations
97+
// by showing the same snackbar twice in rapid succession).
98+
.distinctUntilChanged()
9599
// Emit the last one event of the stream on subscription
96100
// Useful when a View rebinds to the ViewModel after rotation.
97101
.replay(1)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy