nau / jscala

Scala macro that produces JavaScript from Scala code.
MIT License
205 stars 25 forks source link

Improve Seq JsSerializer #22

Closed nafg closed 10 years ago

nafg commented 10 years ago

Currently only Seq[JsExpr] is supported. I suppose you could do xs.map(inject) but with the following any Seq[A] where A can be serialized is supported.

  implicit def seqJsSerializer[A, S[X] <: Seq[X]](implicit ev: JsSerializer[A]): JsSerializer[S[A]] = new JsSerializer[S[A]] {
    def apply(a: S[A]) = JsArray(a.map(ev.apply(_)).toList)
  }

To support the currently supported Seq[JsExpr] you may want to add

  implicit object exprJsSerializer extends JsSerializer[JsExpr] {
    def apply(a: JsExpr) = a
  }
nafg commented 10 years ago

Oh. But that last implicit would break the inject(JsAny) overload.

Which is probably a good thing. It should have a different name, maybe include.

nau commented 10 years ago

Should work.