Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RState -> State #571

Merged
merged 1 commit into from
Jul 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions examples/src/main/kotlin/example/AxiosSearch.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ package example
* This example queries the database of ZIP codes at http://ziptasticapi.com and displays the results.
*/

import kotlinext.js.*
import kotlinx.html.*
import kotlinx.html.js.*
import org.w3c.dom.*
import kotlinext.js.js
import kotlinext.js.jsObject
import kotlinx.html.InputType
import kotlinx.html.js.onChangeFunction
import kotlinx.html.title
import org.w3c.dom.HTMLInputElement
import react.*
import react.dom.*
import kotlin.js.*
import kotlin.js.Promise

@JsModule("axios")
@JsNonModule
Expand Down Expand Up @@ -58,7 +60,7 @@ data class ZipResult(val country: String, val state: String, val city: String)

interface AxiosProps : RProps

interface AxiosState : RState {
interface AxiosState : State {
var zipCode: String
var zipResult: ZipResult
var errorMessage: String
Expand Down
13 changes: 7 additions & 6 deletions examples/src/main/kotlin/example/Product.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ package example
* Date: Nov 24, 2017
*/

import kotlinext.js.*
import kotlinx.html.*
import kotlinx.html.js.*
import org.w3c.dom.*
import kotlinext.js.js
import kotlinx.html.InputType
import kotlinx.html.js.onChangeFunction
import kotlinx.html.js.onClickFunction
import org.w3c.dom.HTMLInputElement
import react.*
import react.dom.*

Expand Down Expand Up @@ -71,7 +72,7 @@ interface SearchBarProps : RProps {
var filterText: String
}

class SearchBar(props: SearchBarProps) : RComponent<SearchBarProps, RState>(props) {
class SearchBar(props: SearchBarProps) : RComponent<SearchBarProps, State>(props) {
override fun RBuilder.render() {
div {
input(type = InputType.text, name = "filterText") {
Expand Down Expand Up @@ -116,7 +117,7 @@ fun RBuilder.searchBar(

interface ProductProps : RProps

interface ProductState : RState {
interface ProductState : State {
var filterText: String
var inStockOnly: Boolean
}
Expand Down
4 changes: 2 additions & 2 deletions examples/src/main/kotlin/example/Quill.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package example
*/

import react.*
import react.dom.*
import react.dom.div

@JsModule("react-quill")
@JsNonModule
Expand All @@ -23,7 +23,7 @@ interface QuillProps : RProps {
var initialText: String
}

interface QuillState : RState {
interface QuillState : State {
var text: String
}

Expand Down
6 changes: 3 additions & 3 deletions examples/src/main/kotlin/example/TicTacToe.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package example

import kotlinx.html.js.*
import kotlinx.html.js.onClickFunction
import react.*
import react.dom.*

Expand All @@ -27,7 +27,7 @@ interface BoardProps : RProps {
var onClick: (Int) -> () -> Unit
}

class Board(props: BoardProps) : RComponent<BoardProps, RState>(props) {
class Board(props: BoardProps) : RComponent<BoardProps, State>(props) {
fun RBuilder.renderSquare(i: Int) {
square(props.squares[i], props.onClick(i))
}
Expand Down Expand Up @@ -62,7 +62,7 @@ fun RBuilder.board(initialSquares: Array<String?>, onClick: (Int) -> () -> Unit)

interface TicTacToeProps : RProps

interface TicTacToeState : RState {
interface TicTacToeState : State {
var history: Array<Array<String?>>
var xIsNext: Boolean
var stepNumber: Int
Expand Down
9 changes: 5 additions & 4 deletions examples/src/main/kotlin/example/Todo.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package example

import kotlinx.html.*
import kotlinx.html.js.*
import org.w3c.dom.*
import kotlinx.html.InputType
import kotlinx.html.js.onChangeFunction
import kotlinx.html.js.onClickFunction
import org.w3c.dom.HTMLInputElement
import react.*
import react.dom.*

Expand All @@ -14,7 +15,7 @@ interface TodoProps : RProps {
var initialItems: List<String?>
}

interface TodoState : RState {
interface TodoState : State {
var items: List<String?>
var text: String
}
Expand Down
2 changes: 1 addition & 1 deletion kotlin-react-redux/src/main/kotlin/react/redux/Imports.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package react.redux
import react.*
import redux.Store

external class Provider : Component<ProviderProps, RState> {
external class Provider : Component<ProviderProps, State> {
override fun render(): ReactElement?
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ external val BrowserRouterComponent: RClass<BrowserRouterProps>
external val SwitchComponent: RClass<RProps>

@JsName("Route")
external class RouteComponent<T : RProps> : Component<RouteProps<T>, RState> {
external class RouteComponent<T : RProps> : Component<RouteProps<T>, State> {
override fun render(): ReactElement?
}

@JsName("Link")
external val LinkComponent: RClass<LinkProps>

@JsName("NavLink")
external class NavLinkComponent<T : RProps> : Component<NavLinkProps<T>, RState> {
external class NavLinkComponent<T : RProps> : Component<NavLinkProps<T>, State> {
override fun render(): ReactElement?
}

Expand Down
2 changes: 1 addition & 1 deletion kotlin-react/src/main/kotlin/react/Component.ext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package react

import kotlinext.js.assign

fun <S : RState> Component<*, S>.setState(buildState: S.() -> Unit) {
fun <S : State> Component<*, S>.setState(buildState: S.() -> Unit) {
setState({ assign(it, buildState) })
}
2 changes: 1 addition & 1 deletion kotlin-react/src/main/kotlin/react/Component.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

package react

abstract external class Component<P : RProps, S : RState>(
abstract external class Component<P : RProps, S : State>(
props: P = definedExternally,
) {
val props: P
Expand Down
6 changes: 3 additions & 3 deletions kotlin-react/src/main/kotlin/react/ComponentClass.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import kotlin.reflect.KClass
// TODO: Should extend RComponentClassStatics, but has problems with generic params
external interface ComponentClass<in P : RProps> :
ComponentType<P>,
RComponentClassStatics<RProps, RState, Context<*>?>
RComponentClassStatics<RProps, State, Context<*>?>

typealias RClass<P> = ComponentClass<P>

val <P : RProps> KClass<out Component<P, *>>.rClass: ComponentClass<P>
get() = js.unsafeCast<ComponentClass<P>>()

external interface RComponentClassStatics<P : RProps, S : RState, C : Context<*>?> {
external interface RComponentClassStatics<P : RProps, S : State, C : Context<*>?> {
var displayName: String?
var defaultProps: P?
var contextType: C
Expand All @@ -34,6 +34,6 @@ external interface RComponentClassStatics<P : RProps, S : RState, C : Context<*>
*
* in your class components
*/
open class RStatics<P : RProps, S : RState, C : Component<P, S>, CTX : Context<*>?>(
open class RStatics<P : RProps, S : State, C : Component<P, S>, CTX : Context<*>?>(
klazz: KClass<C>,
) : RComponentClassStatics<P, S, CTX> by klazz.js.unsafeCast<RComponentClassStatics<P, S, CTX>>()
2 changes: 1 addition & 1 deletion kotlin-react/src/main/kotlin/react/PureComponent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

package react

abstract external class PureComponent<P : RProps, S : RState>(
abstract external class PureComponent<P : RProps, S : State>(
props: P = definedExternally,
) : Component<P, S> {

Expand Down
2 changes: 1 addition & 1 deletion kotlin-react/src/main/kotlin/react/RComponent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package react

import kotlinext.js.jsObject

abstract class RComponent<P : RProps, S : RState> : Component<P, S> {
abstract class RComponent<P : RProps, S : State> : Component<P, S> {
constructor() : super() {
state = jsObject { init() }
}
Expand Down
2 changes: 1 addition & 1 deletion kotlin-react/src/main/kotlin/react/RPureComponent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package react

import kotlinext.js.jsObject

abstract class RPureComponent<P : RProps, S : RState> : PureComponent<P, S> {
abstract class RPureComponent<P : RProps, S : State> : PureComponent<P, S> {
constructor() : super() {
state = jsObject { init() }
}
Expand Down
10 changes: 8 additions & 2 deletions kotlin-react/src/main/kotlin/react/State.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package react

external interface RState
external interface State

class BoxedState<T>(var state: T) : RState
class BoxedState<T>(var state: T) : State

@Deprecated(
message = "Legacy type alias",
replaceWith = ReplaceWith("State", "react.State"),
)
typealias RState = State