diff --git a/workers/src/main/scala/japgolly/webapputil/binary/BinaryJs.scala b/workers/src/main/scala/japgolly/webapputil/binary/BinaryJs.scala index 592e5148d..92078b13e 100644 --- a/workers/src/main/scala/japgolly/webapputil/binary/BinaryJs.scala +++ b/workers/src/main/scala/japgolly/webapputil/binary/BinaryJs.scala @@ -22,8 +22,8 @@ trait BinaryJs { final def base64ToByteBuffer(base64: String): ByteBuffer = { val binstr = window.atob(base64) - val buf = new Int8Array(binstr.length) - var i = 0 + val buf = new Int8Array(binstr.length) + var i = 0 binstr.foreach { ch => buf(i) = ch.toByte i += 1 @@ -33,8 +33,9 @@ trait BinaryJs { final def blobToArrayBuffer(blob: Blob): ArrayBuffer = { var arrayBuffer: ArrayBuffer = null - val fileReader = new FileReader() - fileReader.onload = e => arrayBuffer = e.target.asInstanceOf[js.Dynamic].result.asInstanceOf[ArrayBuffer] + val fileReader = new FileReader() + fileReader.onload = e => + arrayBuffer = e.target.asInstanceOf[js.Dynamic].result.asInstanceOf[ArrayBuffer] fileReader.readAsArrayBuffer(blob) assert(arrayBuffer != null) arrayBuffer @@ -51,7 +52,7 @@ trait BinaryJs { if (bb.hasTypedArray()) bb.typedArray() else if (bb.hasArray) { - var array = bb.array() + var array = bb.array() val offset = bb.arrayOffset() if (limit != array.length) array = array.slice(offset, offset + limit) diff --git a/workers/src/main/scala/japgolly/webapputil/indexeddb/KeyCodec.scala b/workers/src/main/scala/japgolly/webapputil/indexeddb/KeyCodec.scala index 467af5a78..47523b9a0 100644 --- a/workers/src/main/scala/japgolly/webapputil/indexeddb/KeyCodec.scala +++ b/workers/src/main/scala/japgolly/webapputil/indexeddb/KeyCodec.scala @@ -8,19 +8,14 @@ import java.util.UUID import scala.reflect.ClassTag import scala.scalajs.js -final case class KeyCodec[A](encode: A => IndexedDbKey, - decode: IndexedDbKey => CallbackTo[A]) { +final case class KeyCodec[A](encode: A => IndexedDbKey, decode: IndexedDbKey => CallbackTo[A]) { def xmap[B](onDecode: A => B)(onEncode: B => A): KeyCodec[B] = // Delegating because decoding can fail and must be wrapped to be pure - xmapSync( - a => CallbackTo(onDecode(a)))( - onEncode) + xmapSync(a => CallbackTo(onDecode(a)))(onEncode) def xmapSync[B](onDecode: A => CallbackTo[B])(onEncode: B => A): KeyCodec[B] = - KeyCodec[B]( - encode = encode compose onEncode, - decode = decode(_).flatMap(onDecode)) + KeyCodec[B](encode = encode.compose(onEncode), decode = decode(_).flatMap(onDecode)) } object KeyCodec { @@ -34,13 +29,20 @@ object KeyCodec { lazy val long: KeyCodec[Long] = string.xmap(_.toLong)(_.toString) - def primative[A](name: String)(implicit ev: A => IndexedDbKey.Typed, ct: ClassTag[A]): KeyCodec[A] = - apply[A](a => IndexedDbKey(ev(a)), k => CallbackTo( - (k.value: Any) match { - case a: A => a - case x => throw new js.JavaScriptException(s"Invalid IDB key found. $name expected, got: $x") - } - )) + def primative[A]( + name: String + )(implicit ev: A => IndexedDbKey.Typed, ct: ClassTag[A]): KeyCodec[A] = + apply[A]( + a => IndexedDbKey(ev(a)), + k => + CallbackTo( + (k.value: Any) match { + case a: A => a + case x => + throw new js.JavaScriptException(s"Invalid IDB key found. $name expected, got: $x") + } + ) + ) lazy val string: KeyCodec[String] = primative("String") diff --git a/workers/src/main/scala/japgolly/webapputil/indexeddb/TxnDsl.scala b/workers/src/main/scala/japgolly/webapputil/indexeddb/TxnDsl.scala index 2f3cd66d0..f4116bb10 100644 --- a/workers/src/main/scala/japgolly/webapputil/indexeddb/TxnDsl.scala +++ b/workers/src/main/scala/japgolly/webapputil/indexeddb/TxnDsl.scala @@ -44,13 +44,17 @@ sealed abstract class TxnDsl[M <: TxnMode] { final def objectStore[K, V](s: ObjectStoreDef.Sync[K, V]): Txn[M, ObjectStore[K, V]] = TxnStep.GetStore(s) - @inline final def objectStore[K, V](s: ObjectStoreDef.Async[K, V]): Txn[M, ObjectStore[K, s.Value]] = + @inline final def objectStore[K, V]( + s: ObjectStoreDef.Async[K, V] + ): Txn[M, ObjectStore[K, s.Value]] = objectStore(s.sync) @inline final def sequence[G[_], A](txns: G[Txn[M, A]])(implicit G: Traverse[G]): Txn[M, G[A]] = traverse(txns)(identityFn) - @inline final def sequenceIterable[F[x] <: Iterable[x], A](txns: => F[Txn[M, A]])(implicit cbf: BuildFrom[F[Txn[M, A]], A, F[A]]): Txn[M, F[A]] = + @inline final def sequenceIterable[F[x] <: Iterable[x], A](txns: => F[Txn[M, A]])(implicit + cbf: BuildFrom[F[Txn[M, A]], A, F[A]] + ): Txn[M, F[A]] = traverseIterable(txns)(identityFn) @inline final def sequenceIterable_(txns: => Iterable[Txn[M, Any]]): Txn[M, Unit] = @@ -62,13 +66,17 @@ sealed abstract class TxnDsl[M <: TxnMode] { @inline final def sequenceOption_(o: Option[Txn[M, Any]]): Txn[M, Unit] = traverseOption_(o)(identityFn) - final def traverse[G[_], A, B](ga: G[A])(f: A => Txn[M, B])(implicit G: Traverse[G]): Txn[M, G[B]] = + final def traverse[G[_], A, B](ga: G[A])(f: A => Txn[M, B])(implicit + G: Traverse[G] + ): Txn[M, G[B]] = G.traverse(ga)(f.andThen(_.step)) - final def traverseIterable[F[x] <: Iterable[x], A, B](fa: => F[A])(f: A => Txn[M, B])(implicit cbf: BuildFrom[F[A], B, F[B]]): Txn[M, F[B]] = + final def traverseIterable[F[x] <: Iterable[x], A, B]( + fa: => F[A] + )(f: A => Txn[M, B])(implicit cbf: BuildFrom[F[A], B, F[B]]): Txn[M, F[B]] = suspend { val as = fa - val b = cbf.newBuilder(as) + val b = cbf.newBuilder(as) if (as.isEmpty) pure(b.result()) else @@ -121,12 +129,12 @@ sealed abstract class TxnDsl[M <: TxnMode] { object TxnDsl { object RO extends TxnDsl[RO] { - override implicit def catsInstance: Txn.CatsInstance[RO] = Txn.catsInstance(this) + override implicit def catsInstance: Txn.CatsInstance[RO] = Txn.catsInstance(this) override protected implicit def autoWrapStepRO[B](s: TxnStep[RO, B]): Txn[RO, B] = Txn(s) } object RW extends TxnDsl[RW] { - override implicit def catsInstance: Txn.CatsInstance[RW] = Txn.catsInstance(this) + override implicit def catsInstance: Txn.CatsInstance[RW] = Txn.catsInstance(this) override protected implicit def autoWrapStepRO[B](s: TxnStep[RO, B]): Txn[RO, B] = Txn(s) } }