React-Kotlin包装setState方法

在这里的反应文档:

https://facebook.github.io/react/docs/state-and-lifecycle.html#state-updates-may-be-asynchronous

它说下面的代码是不安全的,因为状态是异步更新的:

this.setState({ counter: this.state.counter + this.props.increment, }); 

而是通过像以前的状态和道具:

 this.setState(function(prevState, props) { return { counter: prevState.counter + props.increment }; }); 

但是,位于这里的React-Kotlin包装:

https://github.com/Kotlin/kotlin-fullstack-sample/tree/master/frontend/src/org/jetbrains/react

状态更改是作为状态的扩展函数传入的,它修改了状态对象上的variables:

 //Located in the ReactComponent class in ReactComponent.kt fun setState(builder: S.() -> Unit) { ... } 

如果我在Kotlin中像这样调用setState函数:

 setState { counter: state.counter + props.increment } 

这不等于上面的不安全方法吗? 在React-Kotlin包装器中是不是需要这样执行?

 fun setState(builder: S.(prevState: S, props: P) -> Unit) { ... } 

然后这样叫?

 setState { prevState, props -> counter: prevState.counter + props.increment } 

如果你想得到一个setState的结果,那么你必须调用setState(newState,callback)。

可能的是,这个React绑定不仅仅是一个包装反应。 我认为,这个反应是对真实反应的一个门面。