Skip to content

Instantly share code, notes, and snippets.

@sockeqwe
Created February 28, 2017 00:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sockeqwe/363f002307afcd136ac8b174fe7cc729 to your computer and use it in GitHub Desktop.
Save sockeqwe/363f002307afcd136ac8b174fe7cc729 to your computer and use it in GitHub Desktop.
class FirstPageLoading implements PartialStateChanges {
@Override
public HomeViewState computeNewState(HomeViewState previousState)
return previousState.builder()
.firstPageLoading(true)
.firstPageError(null)
.build();
}
}
interface PartialStateChanges {
HomeViewState computeNewState(HomeViewState previousState)
}
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();
}
}
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