Permalink
Browse files

Complete and final removal of uPickle in favor of Circe (Resolves #38).

  • Loading branch information...
darkfrog26 committed Aug 8, 2017
1 parent 25134f1 commit b784226f9a8c615a3a39a0d05b8af375eb0a7224
@@ -7,6 +7,7 @@ import io.youi.app.sourceMap.ErrorTrace
import org.scalajs.dom._
import io.youi.dom._
import io.youi.net.URL
import profig.JsonUtil
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
@@ -49,8 +50,8 @@ object ClientApplication {
}
def sendError(error: JavaScriptError): Future[XMLHttpRequest] = {
val formData = new FormData
val json = upickle.default.write[JavaScriptError](error)
formData.append("json", json)
val jsonString = JsonUtil.toJsonString(error)
formData.append("json", jsonString)
val request = new AjaxRequest(History.url().replacePathAndParams("/clientError"), data = Some(formData))
request.send()
}
@@ -74,7 +74,7 @@ object ErrorTrace extends LogHandler {
}
private def map(sourceMapConsumer: SourceMapConsumer, line: Int, column: Int): SourcePosition = {
val position = js.JSON.parse(upickle.default.write(JavaScriptPosition(line, column))).asInstanceOf[js.Object]
val position = js.JSON.parse(profig.JsonUtil.toJsonString(JavaScriptPosition(line, column))).asInstanceOf[js.Object]
sourceMapConsumer.originalPositionFor(position)
}
@@ -12,7 +12,7 @@ import io.youi.{JavaScriptError, Priority, http}
import net.sf.uadetector.UserAgentType
import net.sf.uadetector.service.UADetectorServiceFactory
import org.powerscala.io._
import profig.ConfigApplication
import profig.{ConfigApplication, JsonUtil}
import reactify.{Channel, Var}
import scala.concurrent.ExecutionContext.Implicits.global
@@ -65,8 +65,8 @@ trait ServerApplication extends YouIApplication with Server with ConfigApplicati
content match {
case Some(requestContent) => requestContent match {
case formData: FormDataContent => {
val json = formData.string("json").value
val jsError = upickle.default.read[JavaScriptError](json)
val jsonString = formData.string("json").value
val jsError = JsonUtil.fromJsonString[JavaScriptError](jsonString)
val userAgentString = Headers.Request.`User-Agent`.value(httpConnection.request.headers).getOrElse("")
val userAgent = userAgentParser.parse(userAgentString)
@@ -7,7 +7,7 @@ resolvers in ThisBuild += Resolver.sonatypeRepo("releases")
resolvers in ThisBuild += Resolver.sonatypeRepo("snapshots")
scalacOptions in ThisBuild ++= Seq("-unchecked", "-deprecation")
val profigVersion = "1.1.1"
val profigVersion = "1.1.2"
val pixiJsVersion = "4.5.3"
val scribeVersion = "1.4.5"
val powerScalaVersion = "2.0.5"
@@ -19,7 +19,6 @@ val httpMimeVersion = "4.5.3"
val circeVersion = "0.8.0"
val uaDetectorVersion = "2014.10"
val undertowVersion = "1.4.18.Final"
val uPickleVersion = "0.4.4"
val closureCompilerVersion = "v20170423"
val hasherVersion = "1.2.1"
val canvgVersion = "1.4.0_1"
@@ -149,7 +148,6 @@ lazy val communication = crossProject.in(file("communication"))
.settings(
name := "youi-communication",
libraryDependencies ++= Seq(
"com.lihaoyi" %%% "upickle" % uPickleVersion,
"org.scalactic" %%% "scalactic" % scalacticVersion,
"org.scalatest" %%% "scalatest" % scalaTestVersion % "test"
)
@@ -1,5 +1,7 @@
package io.youi.communication
import profig.JsonUtil
case class CommunicationMessage(messageType: Int,
endPoint: String,
invocationId: Int,
@@ -8,7 +10,7 @@ case class CommunicationMessage(messageType: Int,
lazy val parsableString: String = {
val message = error match {
case Some(e) => s"0:$e"
case None => s"1:${upickle.default.write(content)}"
case None => s"1:${JsonUtil.toJsonString(content)}"
}
s"$messageType:[$endPoint]:$invocationId:$message"
}
@@ -25,7 +27,8 @@ object CommunicationMessage {
case MessageRegex(messageType, endPoint, invocationId, success, contentJSON) => {
val successful = success.toInt == 1
val (content, error) = if (successful) {
upickle.default.read[List[String]](contentJSON) -> None
val list = JsonUtil.fromJsonString[List[String]](contentJSON)
list -> None
} else {
Nil -> Some(contentJSON)
}
@@ -27,14 +27,15 @@ object Macros {
}
v.attach { value =>
if (!modifying.get()) {
val json = upickle.default.write[$t](value)
val message = CommunicationMessage(CommunicationMessage.SharedVariable, $endPoint, 0, List(json), None)
val jsonString = profig.JsonUtil.toJsonString[$t](value)
val message = CommunicationMessage(CommunicationMessage.SharedVariable, $endPoint, 0, List(jsonString), None)
comm.send := message
}
}
comm.receive.attach { message =>
if (message.endPoint == $endPoint && message.messageType == CommunicationMessage.SharedVariable) {
val value = upickle.default.read[$t](message.content.head)
val jsonString = message.content.head
val value = profig.JsonUtil.fromJsonString[$t](jsonString)
modifying.set(true)
try {
v := value
@@ -88,21 +89,25 @@ object Macros {
context.abort(context.enclosingPosition, s"$symbol is defined as a @client method, but is defined in the server.")
}
val params = args.zipWithIndex.map {
case (arg, index) => q"upickle.default.read[${arg.typeSignature.resultType}](message.content($index))"
case (arg, index) =>
q"""
val jsonString = message.content($index)
profig.JsonUtil.fromJsonString[${arg.typeSignature.resultType}](jsonString)
"""
}
if (params.nonEmpty) {
q"""
comm.onEndPoint($endPoint) { message =>
${m.name}(..$params).map { response =>
upickle.default.write[$resultType](response)
profig.JsonUtil.toJsonString[$resultType](response)
}
}
"""
} else {
q"""
comm.onEndPoint($endPoint) { message =>
${m.name}.map { response =>
upickle.default.write[$resultType](response)
profig.JsonUtil.toJsonString[$resultType](response)
}
}
"""
@@ -118,14 +123,14 @@ object Macros {
}
val params = args.map { arg =>
val argName = arg.name.toTermName
q"upickle.default.write[${arg.typeSignature.resultType}]($argName)"
q"profig.JsonUtil.toJsonString[${arg.typeSignature.resultType}]($argName)"
}
q"""
override def ${m.name}(..$argList): scala.concurrent.Future[$resultType] = {
val invocationId = comm.nextId()
comm.send := io.youi.communication.CommunicationMessage(io.youi.communication.CommunicationMessage.MethodRequest, $endPoint, invocationId, List(..$params), None)
comm.onInvocation[$resultType](invocationId)( message => {
upickle.default.read[$resultType](message.content.head)
profig.JsonUtil.fromJsonString[$resultType](message.content.head)
})
}
"""
2 wip.md
@@ -11,7 +11,7 @@
* [ ] VerticalLayout
* [X] Update dom Template to utilize Profig instead of limiting to environment variable for load path
* [X] New `spatial` package to do matrix and other spatial math
* [ ] Remove uPickle and rely exclusively on Circe for pickling
* [X] Remove uPickle and rely exclusively on Circe for pickling
* [X] Add better functionality to build FormDataContent
* [X] Support multipart form posting in youi-client
* [X] Update URL interpolator to only accept literals for proper compile-time validation

0 comments on commit b784226

Please sign in to comment.