Created
March 25, 2017 21:09
-
-
Save dimart/30d977ae22118d2d13753b6ac910ecee to your computer and use it in GitHub Desktop.
Basic facade && Basic editor react-component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=========================================== | |
========= Basic facade for Monaco ========= | |
=========================================== | |
package monaco | |
import org.scalajs.dom.raw.HTMLElement | |
import scala.scalajs.js | |
import scala.scalajs.js.UndefOr | |
import scala.scalajs.js.annotation.JSName | |
// @JSImport("min/vs/editor/editor.main", JSImport.Namespace) | |
@js.native | |
@JSName("monaco.editor") | |
object Editor extends js.Object { | |
def create( | |
domElement: HTMLElement, | |
options: UndefOr[js.Object], | |
_override: UndefOr[js.Object] | |
): js.Any = js.native | |
} | |
=========================================== | |
====== Monaco Editor React component ====== | |
=========================================== | |
package com.olegych.scastie.client | |
import japgolly.scalajs.react._ | |
import japgolly.scalajs.react.vdom.all._ | |
import org.scalajs.dom | |
import org.scalajs.dom.raw.HTMLElement | |
object MonacoEditor { | |
private val component = | |
ReactComponentB[(AppState, AppBackend)]("MonacoEditor").render_P { | |
case (state, backend) => { | |
div(`id` := s"container") | |
} | |
}.componentDidMount({ | |
case v => Callback { | |
monaco.Editor.create(dom.document.getElementById("container").asInstanceOf[HTMLElement], null, null) | |
} | |
} | |
).build | |
def apply(state: AppState, backend: AppBackend) = component((state, backend)) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment