Created
July 14, 2017 17:44
-
-
Save marcusradell/ff4f47342eaffa6b1a6f7d3073057637 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
// Imperative, pure, and testable | |
const pluckColId = ({colId}) => colId | |
const columnsInSet => columns => ({colId}) => columns.has(colId) | |
// Declarative | |
const colIds = agGridStateManager.columnState.map(pluckColId) | |
const columnsInGrid = new Set(allColumns.map(pluckColId)) | |
const columnState = agGridStateManager.columnState.filter(columnsInSet(columnsInGrid)) | |
// Effect | |
api.setColumnState(columnState) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The declarative part is usually just one expression, but I didn't know the context around the application to do that.
Also, the effect is better to inject from the outside for testability.
Overall, this could make code easier to reason about from an FP perspective. At the cost of being harder to reason about due to an increased level of indirection. YMMV.
Usually the declarative part is close to certain to be bug free since it only composes functions.