diff --git a/CHANGELOG.md b/CHANGELOG.md index 348f53a3..b8e58b78 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,13 @@ # Changelog ## vNEXT +### Highlights :tada: ++ Improve experience using `ReactElement`s within first-order types such as Map and List [PR #285](https://github.com/shadaj/slinky/pull/285) ++ Support [React Native's Keyboard API](https://facebook.github.io/react-native/docs/keyboard) [PR #293](https://github.com/shadaj/slinky/pull/293) + ### Bug Fixes ++ Fix crashes when calling `setState` on a component with `Props` set to some subtype of `Function1` [PR #295](https://github.com/shadaj/slinky/pull/295) + Support `useCallback` with a function that takes arguments [PR #290](https://github.com/shadaj/slinky/pull/290) -+ Fix issues around using ReactElements within first-order types e.g. Map, List [PR #285](https://github.com/shadaj/slinky/pull/285) -+ Support [React Native's Keyboard API](https://facebook.github.io/react-native/docs/keyboard) via a scalajs facade [PR #293](https://github.com/shadaj/slinky/pull/293) ## [v0.6.2](https://slinky.dev) ### Highlights :tada: diff --git a/core/src/main/scala/slinky/core/DefinitionBase.scala b/core/src/main/scala/slinky/core/DefinitionBase.scala index 767902db..1577464d 100644 --- a/core/src/main/scala/slinky/core/DefinitionBase.scala +++ b/core/src/main/scala/slinky/core/DefinitionBase.scala @@ -57,7 +57,7 @@ abstract class DefinitionBase[Props, State, Snapshot](jsProps: js.Object) extend readStateValue(this.asInstanceOf[PrivateComponentClass].stateR) } - @JSName("setState_scala") + @JSName("setState_scala_1") @inline final def setState(s: State): Unit = { val stateObject = if (BaseComponentWrapper.scalaComponentWritingEnabled) { writeWithWrappingAdjustment(stateWriter)(s) @@ -66,7 +66,7 @@ abstract class DefinitionBase[Props, State, Snapshot](jsProps: js.Object) extend this.asInstanceOf[PrivateComponentClass].setStateR(stateObject) } - @JSName("setState_scala") + @JSName("setState_scala_2") @inline final def setState(fn: State => State): Unit = { this.asInstanceOf[PrivateComponentClass].setStateR((ps: js.Object) => { val s = fn(readStateValue(ps)) @@ -76,7 +76,7 @@ abstract class DefinitionBase[Props, State, Snapshot](jsProps: js.Object) extend }) } - @JSName("setState_scala") + @JSName("setState_scala_3") @inline final def setState(fn: (State, Props) => State): Unit = { this.asInstanceOf[PrivateComponentClass].setStateR((ps: js.Object, p: js.Object) => { val s = fn(readStateValue(ps), readPropsValue(p)) @@ -86,7 +86,7 @@ abstract class DefinitionBase[Props, State, Snapshot](jsProps: js.Object) extend }) } - @JSName("setState_scala") + @JSName("setState_scala_4") @inline final def setState(s: State, callback: () => Unit): Unit = { val stateObject = if (BaseComponentWrapper.scalaComponentWritingEnabled) { writeWithWrappingAdjustment(stateWriter)(s) @@ -94,7 +94,7 @@ abstract class DefinitionBase[Props, State, Snapshot](jsProps: js.Object) extend this.asInstanceOf[PrivateComponentClass].setStateR(stateObject, callback) } - @JSName("setState_scala") + @JSName("setState_scala_5") @inline final def setState(fn: State => State, callback: () => Unit): Unit = { this.asInstanceOf[PrivateComponentClass].setStateR((ps: js.Object) => { val s = fn(readStateValue(ps)) @@ -104,7 +104,7 @@ abstract class DefinitionBase[Props, State, Snapshot](jsProps: js.Object) extend }, callback) } - @JSName("setState_scala") + @JSName("setState_scala_6") @inline final def setState(fn: (State, Props) => State, callback: () => Unit): Unit = { this.asInstanceOf[PrivateComponentClass].setStateR((ps: js.Object, p: js.Object) => { val s = fn(readStateValue(ps), readPropsValue(p)) @@ -137,7 +137,6 @@ abstract class DefinitionBase[Props, State, Snapshot](jsProps: js.Object) extend def componentDidCatch(error: js.Error, info: ErrorBoundaryInfo): Unit = {} - @JSName("render") def render(): ReactElement if (defaultBase != null) { diff --git a/project/build.properties b/project/build.properties index c0bab049..8522443d 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.2.8 +sbt.version=1.3.2 diff --git a/tests/src/test/scala/slinky/core/ComponentTest.scala b/tests/src/test/scala/slinky/core/ComponentTest.scala index 2baf3688..20866b5e 100644 --- a/tests/src/test/scala/slinky/core/ComponentTest.scala +++ b/tests/src/test/scala/slinky/core/ComponentTest.scala @@ -55,22 +55,22 @@ object TestComponentExtraApply extends ComponentWrapper { } } -object TestComponentForSetStateCallback extends ComponentWrapper { - type Props = Int => Unit - type State = Int +object TestComponentForSeqState extends ComponentWrapper { + type Props = () => Unit + type State = Seq[String] class Def(jsProps: js.Object) extends Definition(jsProps) { - override def initialState: Int = 0 + override def initialState = Seq.empty override def componentDidMount(): Unit = { - setState((s, p) => { - s + 1 - }, () => { - props.apply(state) - }) + setState(state :+ "hello") } - override def render(): ReactElement = { + override def render() = { + if (state.nonEmpty) { + props.apply() + } + null } } @@ -319,6 +319,17 @@ class ComponentTest extends AsyncFunSuite { promise.future } + test("setState with Seq state runs correct overloaded definition") { + val promise: Promise[Assertion] = Promise() + + ReactDOM.render( + TestComponentForSeqState(() => promise.success(assert(true))), + dom.document.createElement("div") + ) + + promise.future + } + test("Can construct a component and provide key") { val element: ReactElement = TestComponent(_ => ()).withKey("test") assert(element.asInstanceOf[js.Dynamic].key.toString == "test")