Skip to content
Permalink
Browse files

Store hot reloading proxies in a module to support Scala.js 1.0

  • Loading branch information
shadaj committed Mar 1, 2020
1 parent 9c467ad commit 224adc1e57681a6695b54078de6c8a2edbe260ce
Showing with 15 additions and 7 deletions.
  1. +2 −0 CHANGELOG.md
  2. +13 −7 hot/src/main/scala/slinky/hot/package.scala
@@ -1,6 +1,8 @@
# Changelog

## vNEXT
+ Fix crashes with class components when emitting ES2015 code [PR #335](https://github.com/shadaj/slinky/pull/335)
+ Support hot reloading when using Scala.js 1.0 [PR #336](https://github.com/shadaj/slinky/pull/336)

## [v0.6.4](https://slinky.dev)
### Highlights :tada:
@@ -7,29 +7,35 @@ import scala.scalajs.js

package object hot {
def initialize(): Unit = {
if (js.isUndefined(js.Dynamic.global.proxies)) {
js.Dynamic.global.proxies = js.Dynamic.literal()
}
val dynamicReactProxyModule = ReactProxy.asInstanceOf[js.Dynamic]
val proxyObject: js.Dynamic =
if (js.isUndefined(dynamicReactProxyModule._proxies)) {
val newProxyStore = js.Dynamic.literal()
dynamicReactProxyModule.proxies = newProxyStore
newProxyStore
} else {
dynamicReactProxyModule.proxies
}

BaseComponentWrapper.insertMiddleware { (constructor, component) =>
val componentName = component.asInstanceOf[BaseComponentWrapper].getClass.getName

if (js.isUndefined(component.asInstanceOf[js.Dynamic]._hot)) {
component.asInstanceOf[js.Dynamic]._hot = true

if (js.isUndefined(js.Dynamic.global.proxies.selectDynamic(componentName))) {
js.Dynamic.global.proxies.updateDynamic(componentName)(ReactProxy.createProxy(constructor))
if (js.isUndefined(proxyObject.selectDynamic(componentName))) {
proxyObject.updateDynamic(componentName)(ReactProxy.createProxy(constructor))
} else {
val forceUpdate = ReactProxy.getForceUpdate(ReactRaw)
js.Dynamic.global.proxies
proxyObject
.selectDynamic(componentName)
.update(constructor)
.asInstanceOf[js.Array[js.Object]]
.foreach(o => forceUpdate(o))
}
}

js.Dynamic.global.proxies.selectDynamic(componentName).get().asInstanceOf[js.Object]
proxyObject.selectDynamic(componentName).get().asInstanceOf[js.Object]
}

BaseComponentWrapper.enableScalaComponentWriting()

0 comments on commit 224adc1

Please sign in to comment.
You can’t perform that action at this time.