Skip to content

Commit

Permalink
Add reader/writer for anything that extends js.Any, fix #35 (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
shadaj authored Nov 19, 2017
1 parent 6c49fac commit c39fb5e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
+ Add support for generating `Reader` and `Writer` for sealed traits, value classes, and case objects (through a Magnolia upgrade) [PR #45](https://github.com/shadaj/slinky/pull/45)
+ Fix bug with hot loading not updating instances of readers and writers [PR #49](https://github.com/shadaj/slinky/pull/49)
+ Fix bug with hot loading using the wrong proxy component when there are multiple components classes in the tree [PR #50](https://github.com/shadaj/slinky/pull/50)
+ Add support for reading and writing js.Dynamic (and anything that extends js.Any) [PR #51](https://github.com/shadaj/slinky/pull/51)

### `@react` macro annotation (experimental)
One of Slinky's main goals is to have React components written in Scala look very similar to ES6. In version 0.1.x, Slinky required
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/scala/me/shadaj/slinky/core/ReadWrite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ trait Reader[P] {
}

object Reader {
implicit def objectReader[T <: js.Object]: Reader[T] = (s, root) => (if (root) {
implicit def jsAnyReader[T <: js.Any]: Reader[T] = (s, root) => (if (root) {
s.asInstanceOf[js.Dynamic].value
} else {
s
Expand Down Expand Up @@ -184,10 +184,10 @@ trait Writer[P] {
}

object Writer {
implicit def objectWriter[T <: js.Object]: Writer[T] = (s, root) => if (root) {
implicit def jsAnyWriter[T <: js.Any]: Writer[T] = (s, root) => if (root) {
js.Dynamic.literal("value" -> s)
} else {
s
s.asInstanceOf[js.Object]
}

implicit val unitWriter: Writer[Unit] = (_, _) => js.Dynamic.literal()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ class ReaderWriterTest extends FunSuite {
readWrittenSame(1D)
}

test("Read/write - js.Dynamic") {
readWrittenSame(js.Dynamic.literal(a = 1))
}

test("Read/write - js.UndefOr") {
val defined: js.UndefOr[List[Int]] = List(1)
readWrittenSame(defined)
Expand Down

0 comments on commit c39fb5e

Please sign in to comment.