Skip to content

Instantly share code, notes, and snippets.

@elyphas
Created May 29, 2020 21:43
Show Gist options
  • Select an option

  • Save elyphas/9c90eaa477cc45f7ef4c8ac929aa4b67 to your computer and use it in GitHub Desktop.

Select an option

Save elyphas/9c90eaa477cc45f7ef4c8ac929aa4b67 to your computer and use it in GitHub Desktop.
case class State( //items: Map[Int, Map[String, Any]],
items: List[HList] = List.empty[HNil],
defaultValues: Option[Map[String, String]],
rowActive: Int,
itemNew: ItemNew,
transition: (Int, Int) = (0,0) )
val reduce: Reducer[ActionsStore, State] = Reducer {
case (s, Clean) =>
s
//s.copy(items = Map.empty[Int, Map[String, Any]])
case (s, SetDefaultValues(defaultValues)) => s.copy(defaultValues = Some(defaultValues))
case (s, UpdateLstItems(lst)) => //lst.size start on 1 but, others types start on 0.
/*val r = lst.size
val lstPlusNew = s.defaultValues match {
case Some(value) =>
val newVal = (r -> (Map("renglon" -> (r + 1).toString()) ++ value))
lst + newVal
case None => lst + ( r -> Map("renglon" -> (r + 1).toString() ) )
}
s.copy(items = lstPlusNew, rowActive = r)*/
s
case (s, UpdateRowActive(r)) => s.copy(rowActive = r)
case (s, InsertItem(r)) =>
/*val newItem = ( r -> s.defaultValues.getOrElse(Map.empty[String, Any]))
val itemsUpdated = s.items + newItem
s.copy( items = itemsUpdated, rowActive = (r + 1), itemNew = s.itemNew.copy(row = r))*/
s
case (s, UpdateItem(row, key, value, colTransition)) =>
/*val rowtoUpdate = row.getOrElse(s.rowActive)
val curItem = s.items.getOrElse(rowtoUpdate, Map.empty[String, Any])
val newItem: (Int, Map[String, Any]) = (rowtoUpdate -> (curItem + (key -> value)))
val state2 = colTransition match {
case Some(col) =>
s.copy(transition = ( s.rowActive, col))
case None => s
}
state2.copy ( items = s.items + newItem) */
s
case (s, DeleteItem(r)) =>
/*val curItem = s.items.getOrElse(r, Map.empty[String, Any])
s.copy(items = (s.items - r), rowActive = (r - 1))*/
s
case (s, UpdateTransitionColumn(col)) => s.copy(transition = (s.rowActive, col))
case (s, otros) =>
println ( s"¡&#%! Algo malo paso y no sabemos que ¡&#%! action: $otros" )
s
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment