forked from trungfinity/scalajs-graphql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
146d17d
commit 69d2590
Showing
11 changed files
with
115 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...les/apollo/react-apollo/src/main/scala/anduin/scalajs/react/apollo/ApolloQueryProps.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (C) 2017 Anduin Transactions, Inc. | ||
|
||
package anduin.scalajs.react.apollo | ||
|
||
import scala.scalajs.js | ||
|
||
import anduin.scalajs.noton.Decoder | ||
import anduin.scalajs.noton.generic.deriveDecoder | ||
|
||
final case class ApolloQueryProps[Data]( | ||
data: Option[Data], | ||
loading: Boolean | ||
)( | ||
raw: js.Any | ||
) | ||
|
||
object ApolloQueryProps { | ||
|
||
implicit def decoder[Data: Decoder]: Decoder[ApolloQueryProps[Data]] = { | ||
deriveDecoder[ApolloQueryProps[Data]] | ||
} | ||
} |
12 changes: 0 additions & 12 deletions
12
modules/apollo/react-apollo/src/main/scala/anduin/scalajs/react/apollo/GraphqlTag.scala
This file was deleted.
Oops, something went wrong.
56 changes: 56 additions & 0 deletions
56
...apollo/react-apollo/src/main/scala/anduin/scalajs/react/apollo/HigherOrderComponent.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright (C) 2017 Anduin Transactions, Inc. | ||
|
||
package anduin.scalajs.react.apollo | ||
|
||
import scala.language.higherKinds | ||
import scala.scalajs.js | ||
|
||
import japgolly.scalajs.react.{Children => ChildrenType} | ||
import japgolly.scalajs.react.internal.Box | ||
|
||
import anduin.scalajs.noton.{Decoder, Encoder} | ||
|
||
// scalastyle:off underscore.import | ||
import japgolly.scalajs.react._ | ||
import japgolly.scalajs.react.vdom.html_<^._ | ||
// scalastyle:on underscore.import | ||
|
||
final class HigherOrderComponent[Props, ChildProps]( | ||
raw: internal.HigherOrderComponent[js.Object, js.Object] | ||
)( | ||
implicit encoder: Encoder[Props], | ||
decoder: Decoder[ChildProps] | ||
) { | ||
|
||
def apply[Ctor[-p, +u] <: CtorType[p, u], Children <: ChildrenType]( | ||
component: ScalaComponent[ChildProps, _, _, Ctor] | ||
)( | ||
implicit childCtor: CtorType.Summoner.Aux[Box[ChildProps], Children, Ctor], | ||
ctor: CtorType.Summoner[js.Object, Children] | ||
): JsComponent.ComponentWithRoot[ // scalastyle:ignore no.whitespace.after.left.bracket | ||
Props, | ||
ctor.CT, | ||
JsComponent.Unmounted[js.Object, Null], | ||
js.Object, | ||
ctor.CT, | ||
JsComponent.Unmounted[js.Object, Null] | ||
] = { | ||
val render = { raw: js.Any => | ||
decoder(raw) match { | ||
case Right(childProps) => | ||
val children = PropsChildren | ||
.fromRawProps(raw.asInstanceOf[js.Object]) // scalastyle:ignore token | ||
.toList | ||
.map(VdomNode.apply) | ||
component.ctor.applyGeneric(childProps)(children: _*).raw | ||
|
||
case Left(throwable) => | ||
<.span(throwable.getMessage) | ||
} | ||
} | ||
|
||
JsComponent[js.Object, Children, Null](raw(render)).cmapCtorProps { props: Props => | ||
encoder(props).asInstanceOf[js.Object] // scalastyle:ignore token | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters