Skip to content

Instantly share code, notes, and snippets.

@theKashey
Created April 15, 2018 11:02
Show Gist options
  • Save theKashey/4802b0e9bcc448f792955699042ca1f7 to your computer and use it in GitHub Desktop.
Save theKashey/4802b0e9bcc448f792955699042ca1f7 to your computer and use it in GitHub Desktop.
Table gDSFP+flow
// base - https://github.com/reactjs/rfcs/pull/40#discussion_r180818891
import memoize from "lodash.memoize";
import flow from "lodash.flow";
class Example {
getSortedData = memoize((list, sortFn) => list.slice().sort(sortFn))
getPagedData = memoize((list, page) => list.slice(page*10, (page+1)*10))
render() {
const theFlow = flow(
// sort
(data) => this.getSortedData(data,this.props.sort)
// slice
(sorted) => this.getPagedData(sorted, this.props.page)
);
const paged = theFlow(this.props.data);
// Render with this.props, this.state, and derived values ...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment