These are chat archives for japgolly/scalacss

26th
Jun 2015
Nick Childers
@Voltir
Jun 26 2015 18:41
So, I discovered I can do somthing kind of interesting and was wondering what the implications are
I am porting some flexbox code to scalacss that does a grid layout
i have a function grid and a function cell that return styleA
i noticed i generated something like 35+ styles of the form AppStyles-cell-x in the test case i was looking at
then I wrote this:
  //Defaults
  private var fixedCellCache: Map[(SpacingModifier,AlignModifier,SizeModifier),StyleA] = Map.empty

  def cell(
    spacing: SpacingModifier = Gutter,
    aligned: AlignModifier = NotSet,
    sizing: SizeModifier = Fit
  ): StyleA = {
    fixedCellCache.getOrElse((spacing,aligned,sizing),{
      val cellStyle = style(cellFixed(spacing, aligned, sizing))
      fixedCellCache = fixedCellCache + ((spacing,aligned,sizing) -> cellStyle)
      cellStyle
    })
  }
basically caching the styles so only around 6 get generated (there are apparently 6 unique permutations of cells in the test code)
does this matter at all or should I freely generate new styles on a whim?