bashor
07/29/2020, 11:39 AMSebastian Aigner
07/29/2020, 3:51 PMkotlinx-nodejs
with you, which provides typesafe Node.js API bindings for Kotlin/JS! :kotlin-flag:
You can find installation instructions for kotlinx-nodejs
in the blogpost for 1.4.0-RC or on GitHub.
Have fun experimenting - and don’t forget to report any encountered issues!spierce7
07/30/2020, 2:25 AMfrank
07/30/2020, 10:47 AMval (mensajes, setMensajes) = useState(emptyArray<Json>()) //{ nick, msg, type}
val (users, setUsers) = useState(emptyArray<Json>())
useEffect(listOf(users)) {
socket.on("loginUser") { data ->
console.log("OnloginUser")
val noOfUsers = data["numOfUsers"] as Int
val item = getMsgJson("", getParticipantsMessage(noOfUsers), "log")
val items = mensajes.plus(item)
setMensajes(items) //render 1 time
setUsers(data["usersList"]) //render 2 time
}
}
christophsturm
07/31/2020, 10:39 AMuseKarma
and `useMocha`methods.christophsturm
07/31/2020, 12:38 PMsrc/jsMain/js
and src/jsMain/ts
(like kotlin/jvm supports java sourcecode)Alexander Weickmann
07/31/2020, 10:17 PMjanvladimirmostert
08/01/2020, 9:24 AM@JsExport
@ExperimentalJsExport
class LoginState(
json: String? = null,
) {
now in RC the compiler complains:
e: java.lang.IllegalStateException: Can't find name for declaration FUN SYNTHESIZED_DECLARATION name:LoginState_init_$Create$ visibility:public modality:FINAL <> (json:kotlin.String?, $mask0:<http://kotlin.Int|kotlin.Int>, $marker:kotlin.js.DefaultConstructorMarker?) returnType:com.rezproperty.modules.account.state.LoginState
and neither is adding a second constructor after removing the param from the default constructor?
@JsExport
@ExperimentalJsExport
class LoginState() {
@JsName("LoginStateWithJson")
constructor(json: String): this() {
...
}
e: java.lang.IllegalStateException: Can't find name for declaration FUN SYNTHESIZED_DECLARATION name:LoginState_init_$Create$ visibility:public modality:FINAL <> (json:kotlin.String) returnType:com.rezproperty.modules.account.state.LoginState
Jorrit
08/01/2020, 7:06 PMJorrit
08/02/2020, 8:47 PMkotlin.js.compiler=ir
in gradle.properties
, all is fine generally, but if I use --continuous
in my the run configuration for the run
gradle task, the first compile works, but as soon as I change a file and save, the build crashes with a file not found on the <ModuleName>.js file. Restarting the task again works fine. It seems doubtful I'm the first to try this, so I'm guessing I'm doing something wrong here. Anyone have an easy answer, or YT ?Jorrit
08/05/2020, 12:37 AMjoin()
to `Uint16Array`:
@JsName("Uin16Array")
public external open class Uint16ArrayX : Uint16Array {
// copy/paste constructors from Uint16Array here
fun join(separator: String = definedExternally): String
}
This seems to work, but it also feels like I need to wash my hands now. I can use an Uint16ArrayX
anywhere a Uint16Array
is asked for. The only caveat is that going from X to original needs an unsafeCast, but that is mildly inconvenient at worst.
I didn't find a way to patch Uint16Array directly. The compiler wont accept external extensions to an external class. Is there a better way to do this than above? Ofcourse I could just (Uint16Array).asDynamic().join(...) but that's not the point of this exercise.
(b) It seems CharArray uses Uint16Array internally (IntArray to Int32Array, etc), but am I correct in my understanding that CharArray's functions are otherwise pure kotlin and not (or rarely) mapped to their Uint16Array counterparts (which aren't declared at this point anyway) ?
(c) For TypedArrays (and a few other things) it seems Kotlin's definitions are a bit outdated/missing. I looked in Kotlin source GitHub to see if I might contribute at some point, but it is unclear to me what comes from where. There's idl files referenced to which the original urls no longer serve (are the kotlin files autogenerated from them .idl or hand-translated?). There are several copies of the definitions as well. Where to start here for possible (far) future pull request ?Jorrit
08/05/2020, 12:54 AMdata class Test(val i: Int, val s: String)
var t = Test(1, "hello")
someJavascriptFunctionExpectingObject(t)
var t = js("{i: 1, s: 'hello'}").unsafeCase<Test>()
In hindsight it seems obvious that this works. But when Googling around for this I ran into all sorts of parsers and lengthy code ending up with the same thing but significantly slower. Is there something wrong with doing it this way, other than losing presence/type checks for the fields? Is this likely to break in unexpected ways (such as?) or is it fine to use in tightly controlled cases?
Thank you for coming to my TED talk 🙂Brandon Saunders
08/05/2020, 10:13 AMconfig.optimization.splitChunks = {
minSize: <someNumber>,
maxSize: <theSameNumber>
};
I get nothing in my distributions folder. If I remove it, the distributions folder gets created on build. Any ideas?Nicholas Bilyk
08/05/2020, 8:40 PMVampire
08/05/2020, 11:28 PMkotlin("js") version "1.3.72"
I called kotlin { target { nodejs() } }
I declared all the dependencies I had in package.json
now with implementation(npm("...", "..."))
Now my current problem is how do I make those dependencies properly usable using Dukat?
I've read you can set the project property kotlin.js.experimental.generateKotlinExternals = true
to enable automatic Dukat magic.
But either this is wrong, or I did something wrong or not fully.
When I run gradlew build
, I get this:
> Task :generateExternals
events.js:187
throw er; // Unhandled 'error' event
^
Error: write EPIPE
at afterWriteDispatched (internal/stream_base_commons.js:150:25)
at writeGeneric (internal/stream_base_commons.js:141:3)
at Socket._writeGeneric (net.js:771:11)
at Socket._write (net.js:783:8)
at doWrite (_stream_writable.js:431:12)
at writeOrBuffer (_stream_writable.js:415:5)
at Socket.Writable.write (_stream_writable.js:305:11)
at Readable.ondata (_stream_readable.js:727:22)
at Readable.emit (events.js:210:5)
at Readable.read (_stream_readable.js:525:10)
Emitted 'error' event on Socket instance at:
at errorOrDestroy (internal/streams/destroy.js:108:12)
at Socket.onerror (_stream_readable.js:759:7)
at Socket.emit (events.js:215:7)
at errorOrDestroy (internal/streams/destroy.js:108:12)
at onwriteError (_stream_writable.js:446:5)
at onwrite (_stream_writable.js:473:5)
at internal/streams/destroy.js:50:7
at Socket._destroy (net.js:664:5)
at Socket.destroy (internal/streams/destroy.js:38:8)
at afterWriteDispatched (internal/stream_base_commons.js:150:17) {
errno: 'EPIPE',
code: 'EPIPE',
syscall: 'write'
}
Peter Fortuin
08/06/2020, 10:44 AMJorrit
08/06/2020, 1:01 PMVampire
08/06/2020, 1:53 PMEPIPE
problem from above solved, I'm a step further, but highly confused.
Maybe someone can shed some light here.
• If I only have implementation(npm("@actions/core", "1.2.4"))
as npm dependency, automatic Dukat runs fine now, producing a core.module_@actions_core.kt
file with the external definitions, but all exported methods are in the default package, not in an npm-package specific package, is that expected or can this be changed? I imagine this could easily cause conflicts if you add more dependencies.
• Also, with only @actions/core
as dependency, it then compiled fine, but doing ./gradlew run
complains with ReferenceError: setFailed is not defined
• Now it gets even uglier, I added the other dependencies I have (or at least had in the TS variant, some are probably superfluous now):
implementation(npm("@actions/cache", "1.0.1"))
implementation(npm("@actions/core", "1.2.4"))
implementation(npm("@actions/exec", "1.0.4"))
implementation(npm("@actions/http-client", "1.0.8"))
implementation(npm("@actions/io", "1.0.2"))
implementation(npm("@actions/tool-cache", "1.6.0"))
implementation(npm("semver", "7.3.2"))
implementation(npm("null-writable", "1.0.5"))
implementation(npm("node-filter-async", "2.0.0"))
and now while Dukat still duly does its work (and produces 316! Kotlin files o_O), the compiler is super unhappy, throwing 802 errors at me.PHondogo
08/07/2020, 8:46 AMfwilhe
08/07/2020, 5:54 PMdarkmoon_uk
08/09/2020, 9:03 AMJohn O'Reilly
08/09/2020, 9:33 AMkotlin-react-router-dom
wrapper ....it looks like correct property gets passed to StationList
but useEffectWithCleanup
block isn't being executed 2nd time I click on a link (so isn't loading the data)....anyone know what I should be doing differently here?Rob Murdock
08/11/2020, 2:31 AMGunslingor
08/11/2020, 5:08 PM@JsModule("grapesjs")
external class Grapes {
fun init(lambda: () -> Unit): Grapes = definedExternally
}
class WebEditorViewController {
val grapes = Grapes().init {
val container = "#gjs"
val fromElement = true
}
}
And here is what the actual JS is supposed to look like, from the hello world examples
const editor = grapesjs.init({
container: '#gjs',
fromElement: true,
height: '300px',
width: 'auto',
storageManager: false,
panels: { defaults: [] },
});
Gunslingor
08/12/2020, 3:18 AMMarc Knaup
08/12/2020, 11:28 AMIntl
functionality?
I’m trying to use Intl.Locale
.Vampire
08/12/2020, 1:31 PMwarning "workspace-aggregator-6f2c6a0d-778d-49e5-9792-0c1b7ca65d3f > setup-wsl > kotlinx-coroutines-core@1.3.8" has incorrect peer dependency "kotlin@1.3.71".
telling me?
Did I do something wrong? Is there a Koltin/JS error? ...?
This is displyed when I have implementation(npm("kotlinx-coroutines-core", "1.3.8"))
and refresh in IntelliJ.
Actually mainly wondering, because I'll replace that with implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-js:1.3.8")
as the npm
variant does not provide navigation to definition.Vampire
08/12/2020, 2:17 PMprocess
in Kotlin/JS for node.js besides using for example private val platform = js("process.platform") as String
Vampire
08/12/2020, 6:28 PMrunBlocking
as it does not exist for Kotlin/JS intentionally.
Actually right now I just declared the fun main()
as suspend fun main()
and it seems to work properly.
Just want to double-check whether this is the correct way. 🙂Mark Iantorno
08/12/2020, 6:43 PMclass FileUploadComponent : RComponent<FileUploadProps, RState>() {
override fun RBuilder.render() {
styledInput(InputType.file, name = "fileUpload", formEncType = InputFormEncType.multipartFormData) {
css {
display = Display.none
}
attrs {
id = "FileUploadInput"
onInputFunction = {
event -> println("onInputFunction :: $event")
val input = document.getElementById("FileUploadInput") as HTMLInputElement
println("VALUE -> ${input.value}")
}
}
}
styledButton {
+"Upload Files"
attrs {
name = "UploadFileButton"
onClickFunction = {
val field = document.getElementById("FileUploadInput") as HTMLInputElement
field.click()
}
}
}
}
}
But that only does one file at a time, and not multiple files. I know if HTML you would just add something like <input id='file-input' type='file' multiple/>
and it would work, but I can't figure out how to add the multiple attribute to this input...
Any help would be greatly appreciated.Mark Iantorno
08/12/2020, 6:43 PMclass FileUploadComponent : RComponent<FileUploadProps, RState>() {
override fun RBuilder.render() {
styledInput(InputType.file, name = "fileUpload", formEncType = InputFormEncType.multipartFormData) {
css {
display = Display.none
}
attrs {
id = "FileUploadInput"
onInputFunction = {
event -> println("onInputFunction :: $event")
val input = document.getElementById("FileUploadInput") as HTMLInputElement
println("VALUE -> ${input.value}")
}
}
}
styledButton {
+"Upload Files"
attrs {
name = "UploadFileButton"
onClickFunction = {
val field = document.getElementById("FileUploadInput") as HTMLInputElement
field.click()
}
}
}
}
}
But that only does one file at a time, and not multiple files. I know if HTML you would just add something like <input id='file-input' type='file' multiple/>
and it would work, but I can't figure out how to add the multiple attribute to this input...
Any help would be greatly appreciated.janvladimirmostert
08/13/2020, 2:42 PMMark Iantorno
08/13/2020, 2:42 PMmultiple = true
in the attrs
sectionjanvladimirmostert
08/13/2020, 2:42 PM