Skip to content

Instantly share code, notes, and snippets.

@elyphas
Created July 1, 2019 20:28
Show Gist options
  • Save elyphas/efa71728497655969521d73a066cdbbf to your computer and use it in GitHub Desktop.
Save elyphas/efa71728497655969521d73a066cdbbf to your computer and use it in GitHub Desktop.
val reduce: (AppState, ActionsStore) => (AppState, Observable[ActionsStore]) = (s, a) => a match {
case CleanStore => (s.copy(lstBienes = LstItems()), Observable.empty)
case UpdateLstItems(lst) =>
(s.copy(lstBienes = lst), Observable.empty)
case InsertItem(item) =>
println("Insertando una fila en el store del LstBienesStore !!!!!!!!!!!!!!!!!!!!")
val newItems: Seq[Renglon] = s.lstBienes.items ++ Seq(item)
(s.copy(lstBienes = s.lstBienes.copy(items = newItems), rowActive = item), Observable.empty )
case UpdateItem(renglon) =>
def condIndex(a: Renglon, b: Renglon): Boolean = {
val genericRenglon1 = Generic[Renglon].to(a)
val genericRenglon2 = Generic[Renglon].to(b)
genericRenglon1.take(3) == genericRenglon2.take(3)
}
val genericRenglon = Generic[Renglon].to(renglon)
val condInd = condIndex(renglon, _: Renglon)
val newListBienes = s.lstBienes.updated(renglon, condInd)
(s.copy(lstBienes = newListBienes), Observable.empty)
case UpdateItem2(f, v) =>
val rowActiveMap = gridcomponent.components.TransformData ( s.rowActive )
val rowActiveMap2 = rowActiveMap + (f -> v)
import components.maptocc._
def to[A]: ConvertHelper[A] = new ConvertHelper[A]
val newRow = to[Renglon].from(rowActiveMap2).getOrElse(Renglon())
def condIndex(a: Renglon, b: Renglon): Boolean = {
val genericRenglon1 = Generic[Renglon].to(a)
val genericRenglon2 = Generic[Renglon].to(b)
genericRenglon1.take(4) == genericRenglon2.take(4)
}
val condInd = condIndex(newRow, _: Renglon)
val newListBienes = s.lstBienes.updated(newRow, condInd)
(s.copy(lstBienes = newListBienes),
Observable.fromFuture {
val payload = Pickle.intoBytes[String](v)
val respondWS = WSMyCelium.ws.send("getArticulo" :: Nil, payload, SendType.WhenConnected, 30 seconds)
respondWS.map {
case Right(value) =>
val unPickle = Unpickle[Either[String, Articulo]].fromBytes(value)
unPickle match {
case Right(value) => UpdateItem2("descripcion_articulo", value.descripcion.getOrElse("no hay descripcion"))
case Left(error) => UpdateItem2("descripcion_articulo", "error al obtener la descripcion del articulo")
}
case Left(value) =>
UpdateItem2("descripcion_articulo", "error al obtener la descripcion del articulo")
}
})
case UpdateRowActive(n) =>
val rowActiv = s.lstBienes.items.filter(f => f.renglon == n).head
println("")
(s.copy(rowActive = rowActiv), Observable.empty)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment