Skip to content

Commit

Permalink
Merge pull request #171 from ScalablyTyped/recognize-react-fc-returni…
Browse files Browse the repository at this point in the history
…ng-any

recognize function components returning `any`
  • Loading branch information
oyvindberg committed Jul 2, 2020
2 parents 5163f41 + f8bebe7 commit c1d4b16
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 3 deletions.
1 change: 0 additions & 1 deletion sbt-converter/src/sbt-test/react/external/build.sbt
Expand Up @@ -15,4 +15,3 @@ lazy val testProject =
scalaVersion := "2.13.2",
organization := "net.leibman",
)

Expand Up @@ -75,6 +75,8 @@ class IdentifyReactComponents(reactNames: ReactNames, parentsResolver: ParentsRe
def maybeMethodComponent(method: MethodTree, owner: ContainerTree, scope: TreeScope): Option[Component] = {
def returnsElement(scope: TreeScope, current: TypeRef): Option[TypeRef] =
if (reactNames.isElement(current.typeName)) Some(current)
else if (current === TypeRef.Any)
Some(current) // unfortunately this conforms on the TS side, let's see how it works out
else if (scope.isAbstract(current)) None
else
current match {
Expand Down
@@ -1,6 +1,6 @@
organization := "org.scalablytyped"
name := "stardust-ui__react-component-event-listener"
version := "0.38.0-ffa70f"
version := "0.38.0-ad5fb5"
scalaVersion := "2.13.2"
enablePlugins(ScalaJSPlugin)
libraryDependencies ++= Seq(
Expand Down
@@ -0,0 +1,47 @@
package typingsJapgolly.stardustUiReactComponentEventListener.components

import japgolly.scalajs.react.Callback
import japgolly.scalajs.react.Children.Varargs
import japgolly.scalajs.react.CtorType.ChildArg
import japgolly.scalajs.react.JsComponent
import japgolly.scalajs.react.Key
import japgolly.scalajs.react.component.Js.MountedWithRawType
import japgolly.scalajs.react.component.Js.RawMounted
import japgolly.scalajs.react.component.Js.UnmountedSimple
import japgolly.scalajs.react.raw.React.RefHandle
import org.scalablytyped.runtime.StringDictionary
import typingsJapgolly.stardustUiReactComponentEventListener.typesMod.EventListenerOptions
import scala.scalajs.js
import scala.scalajs.js.`|`
import scala.scalajs.js.annotation._

object EventListener {
def apply[/* <: typingsJapgolly.stardustUiReactComponentEventListener.typesMod.EventTypes */ T](
listener: /* import warning: importer.ImportType#apply Failed type conversion: / * import warning: transforms.QualifyReferences#resolveTypeRef many Couldn't qualify DocumentEventMap * / any[T] */ /* e */ js.Any => Callback,
targetRef: RefHandle[
/* import warning: transforms.QualifyReferences#resolveTypeRef many Couldn't qualify Node */ js.Any
],
`type`: T,
capture: js.UndefOr[Boolean] = js.undefined,
key: Key = null,
_overrides: StringDictionary[js.Any] = null
)(
children: ChildArg*
): UnmountedSimple[
EventListenerOptions[T],
MountedWithRawType[EventListenerOptions[T], js.Object, RawMounted[EventListenerOptions[T], js.Object]]
] = {
val __obj = js.Dynamic.literal(listener = js.Any.fromFunction1((t0: /* import warning: importer.ImportType#apply Failed type conversion: / * import warning: transforms.QualifyReferences#resolveTypeRef many Couldn't qualify DocumentEventMap * / any[T] */ /* e */ js.Any) => listener(t0).runNow()), targetRef = targetRef.asInstanceOf[js.Any])
__obj.updateDynamic("type")(`type`.asInstanceOf[js.Any])
if (!js.isUndefined(capture)) __obj.updateDynamic("capture")(capture.get.asInstanceOf[js.Any])
if (key != null) __obj.updateDynamic("key")(key.asInstanceOf[js.Any])
if (_overrides != null) js.Dynamic.global.Object.assign(__obj, _overrides)
val f = JsComponent[EventListenerOptions[T], Varargs, js.Object](this.componentImport)
f(__obj.asInstanceOf[EventListenerOptions[T]])(children :_*)
}
@JSImport("@stardust-ui/react-component-event-listener/dist/es/EventListener", JSImport.Default)
@js.native
object componentImport extends js.Object

}

@@ -1,6 +1,6 @@
organization := "org.scalablytyped"
name := "stardust-ui__react-component-event-listener"
version := "0.38.0-dc344e"
version := "0.38.0-8f5a38"
scalaVersion := "2.13.2"
enablePlugins(ScalaJSPlugin)
libraryDependencies ++= Seq(
Expand Down
@@ -0,0 +1,38 @@
package typingsSlinky.stardustUiReactComponentEventListener.components

import slinky.core.facade.ReactRef
import slinky.web.html.`*`.tag
import typingsSlinky.StBuildingComponent
import typingsSlinky.stardustUiReactComponentEventListener.typesMod.EventListenerOptions
import scala.scalajs.js
import scala.scalajs.js.`|`
import scala.scalajs.js.annotation._

object EventListener {
@JSImport("@stardust-ui/react-component-event-listener/dist/es/EventListener", JSImport.Default)
@js.native
object component extends js.Object

@scala.inline
class Builder[/* <: typingsSlinky.stardustUiReactComponentEventListener.typesMod.EventTypes */ T] (val args: js.Array[js.Any])
extends AnyVal
with StBuildingComponent[tag.type, js.Object] {
@scala.inline
def capture(value: Boolean): this.type = set("capture", value.asInstanceOf[js.Any])
}

def withProps[/* <: typingsSlinky.stardustUiReactComponentEventListener.typesMod.EventTypes */ T](p: EventListenerOptions[T]): Builder[T] = new Builder[T](js.Array(this.component, p.asInstanceOf[js.Any]))
@scala.inline
def apply[/* <: typingsSlinky.stardustUiReactComponentEventListener.typesMod.EventTypes */ T](
listener: /* import warning: importer.ImportType#apply Failed type conversion: / * import warning: transforms.QualifyReferences#resolveTypeRef many Couldn't qualify DocumentEventMap * / any[T] */ /* e */ js.Any => Unit,
targetRef: ReactRef[
/* import warning: transforms.QualifyReferences#resolveTypeRef many Couldn't qualify Node */ js.Any
],
`type`: T
): Builder[T] = {
val __props = js.Dynamic.literal(listener = js.Any.fromFunction1(listener), targetRef = targetRef.asInstanceOf[js.Any])
__props.updateDynamic("type")(`type`.asInstanceOf[js.Any])
new Builder[T](js.Array(this.component, __props.asInstanceOf[EventListenerOptions[T]]))
}
}

0 comments on commit c1d4b16

Please sign in to comment.