Skip to content

Instantly share code, notes, and snippets.

@marcusradell
Created July 14, 2017 17:44
Show Gist options
  • Save marcusradell/ff4f47342eaffa6b1a6f7d3073057637 to your computer and use it in GitHub Desktop.
Save marcusradell/ff4f47342eaffa6b1a6f7d3073057637 to your computer and use it in GitHub Desktop.
// 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)
@marcusradell
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment