Created
February 28, 2017 00:58
-
-
Save sockeqwe/363f002307afcd136ac8b174fe7cc729 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FirstPageLoading implements PartialStateChanges { | |
@Override | |
public HomeViewState computeNewState(HomeViewState previousState) | |
return previousState.builder() | |
.firstPageLoading(true) | |
.firstPageError(null) | |
.build(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface PartialStateChanges { | |
HomeViewState computeNewState(HomeViewState previousState) | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PullToRefreshLoaded implements PartialStateChanges { | |
private final List<FeedItem> data; | |
public PullToRefreshLoaded(List<FeedItem> data) { | |
this.data = data; | |
} | |
@Override | |
public HomeViewState computeNewState(HomeViewState previousState) { | |
List<FeedItem> data = new ArrayList<>(); | |
data.addAll(this.data); | |
data.addAll(previousState.getData()); | |
return previousState.builder() | |
.pullToRefreshLoading(false) | |
.pullToRefreshError(null) | |
.data(data) | |
.build(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private HomeViewState viewStateReducer(HomeViewState previousState, PartialStateChanges partialChanges) { | |
return partialChanges.computeNewState(previousState); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment