https://kotlinlang.org logo
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
javascript
  • g

    Grantas33

    04/25/2020, 5:28 PM
    Hello. I'm running a Ktor server with a particular endpoint that responds a CommonDateTime class object. In a kotlin,js client, I'm making a fetch request to the endpoint and I'm trying to parse the JSON to CommonDateTime class like this:
    it.json().await().unsafeCast<CommonDateTime>()
    CommonDateTime:
    expect class CommonDateTime(millis: Long) {
        fun getYear(): Int
    }
    However, calling
    getYear()
    function on a casted instance yields an error:
    TypeError: is not a function
    (since
    unsafeCast
    just uses dynamic JS values). Is there an alternative to
    unsafeCast
    that would actually create the objects from JSON so that I could call its instance methods?
    t
    i
    • 3
    • 2
  • f

    Franco

    04/25/2020, 11:04 PM
    Hi there, I updated to the latest vetrsion of the
    kotlin-wrapper
    libraries and now I'm experiencing a few issues: 1.
    kotlinx.css
    can't be found, but when checking the code in Github the package name doesn't seem to have changed. Does anyone know what happened here? 2. Library dependencies can't be accessed as before and now I have to add them explicitly in my
    build.gradle.kts
    , e.g.,
    kotlin-react-dom
    uses
    kotlin-extensions
    and I could access the latter without adding it in my build file, but now I can't unless I do add it. Was this on purpose or an issue of changing the build files to kts? @turansky I saw that the latest commits are mostly yours so you might know why these things are happening.
    t
    y
    • 3
    • 8
  • p

    Philipp Smorygo [JB]

    04/28/2020, 12:32 AM
    Hello. I’d like to know some stuff about d.ts generation for KJS targets. How can I use `enum class`es in my common code so that I could use it as a regular typescript typed enum and not as a class with bunch of
    ...getInstance()
    fields?
    d
    • 2
    • 1
  • w

    Wolf Logan

    04/28/2020, 6:04 PM
    I've been struggling to get a Kotlin Multiplatform project working with Gradle, and I've run out of ideas. Currently, I can do a
    gradle build
    immediately after a
    gradle clean
    , but if I then make a change to any Kotlin code in the JS source set, the next
    gradle build
    will fail.
    t
    i
    • 3
    • 8
  • s

    Sean Keane

    04/29/2020, 11:37 AM
    Hi All! I seem to have an issue running tests. I have a simple test like the following
    //COMMON CODE
    class CredentialsManagerTest: BaseTest() {
    
        @Test
        fun runTest() = runTest {
            fail()
        }
    
    }
    
    expect abstract class BaseTest(){
        fun <T> runTest(block: suspend CoroutineScope.() -> T)
    }
    
    //JS ACTUAL
    actual abstract class BaseTest actual constructor() {
        actual fun <T> runTest(block: suspend CoroutineScope.() -> T) {
        }
    }
    The test runs in JS
    > Task :common:compileKotlinJs UP-TO-DATE
    > Task :common:jsMainClasses UP-TO-DATE
    > Task :common:compileTestKotlinJs UP-TO-DATE
    > Task :common:compileDevelopmentTestKotlinJs UP-TO-DATE
    > Task :common:jsTestClasses UP-TO-DATE
    > Task :common:jsBrowserTest
    Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
    Use '--warning-mode all' to show the individual deprecation warnings.
    See <https://docs.gradle.org/6.3/userguide/command_line_interface.html#sec:command_line_warnings>
    BUILD SUCCESSFUL in 14s
    I have it setup to use Firefox as the test browser
    browser() {
        webpackTask() {
            mode = org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig.Mode.DEVELOPMENT
            sourceMaps = true
        }
        testTask {
            useKarma { useFirefox() }
            enabled = true
        }
    }
    But the test passes?? It runs the test in the browser and goes green. I cant seem to make it fail? Am I missing something? This is in a Multiplatform Project and has an Android Component also.
    ➕ 1
    i
    r
    • 3
    • 14
  • c

    Chilli

    04/29/2020, 3:49 PM
    Just out of curiosity — how are things like Longs implemented in Kotlin/JS if JavaScript only has floating-point numbers? 🤔
    a
    b
    • 3
    • 3
  • c

    Chilli

    04/29/2020, 5:14 PM
    Also, is it possible to have different source sets for frontend and node.js? (e.g. browserMain and nodeMain)
    b
    i
    • 3
    • 2
  • g

    Grantas33

    04/29/2020, 6:53 PM
    Does anyone have experience in developing large scale apps with kotlin.js? Does it scale well, considering grade plugin outputs just a single js file?
    t
    b
    • 3
    • 3
  • n

    Nick Williams

    04/29/2020, 11:30 PM
    :kotlin:Using Firebase in your Kotlin JS project? You might find this wrapper around the firebase-js-sdk useful: https://github.com/GitLiveApp/firebase-kotlin-sdk
    d
    • 2
    • 4
  • s

    Sean Keane

    04/30/2020, 11:54 AM
    I just posted this on #mockk but maybe someone here has achieved this? I cant seem to find any real examples with JS inclusive and get this error.
    • 1
    • 1
  • v

    v79

    04/30/2020, 12:09 PM
    A quick question about kotlinx-html-js - Is this purely a front-end, Javascript library? And not a tool for me to write Javascript as part of a kotlinx-html block on the server side?
    s
    n
    • 3
    • 10
  • f

    Foso

    05/01/2020, 9:47 AM
    Hi, is there any server framework like Ktor for KotlinJs?
    s
    d
    • 3
    • 5
  • i

    iseki

    05/04/2020, 5:27 AM
    Hi, I have a problem with my code... Browser error me
    closure$handler
    is not a function... But my
    handler
    is a lambda... What's happend. Thank you My code is pasted on: https://paste.ubuntu.com/p/TspvByyRNP/
    ✅ 2
    • 1
    • 1
  • g

    gbaldeck

    05/04/2020, 11:20 PM
    do the kotlin-wrappers support v1.4-M1 and the new IR?
    :yes: 1
    i
    s
    • 3
    • 3
  • r

    rnentjes

    05/05/2020, 11:42 AM
    The produceExecutable option is gone in 1.4-M2-eap-68, is there an alternative?
    s
    r
    t
    • 4
    • 6
  • a

    andrewreitz

    05/05/2020, 10:07 PM
    Has anyone been successful in deploying a kotlin-js project to firebase? If I target nodejs I can’t deploy it due to dependency issues, and if I try to use browser target it looks like webpack messes up the code enough that it won’t actually run, which all the issues with webpack seem to lie with kotor. I added https://kotlinlang.org/docs/reference/javascript-dce.html#known-issue-dce-and-ktor but still not working.
    t
    d
    +2
    • 5
    • 122
  • s

    spierce7

    05/06/2020, 3:01 PM
    I’m compiling my code for react-native. Previously I’ve been using the DCE plugin to get all my js files all in one place, and to ship an app that is as small as possible. It seems like the new direction for DCE is to use the browser target, but that compilation seems to run things through webpack. I don’t think I need webpack as react-native has it’s own bundler that I have to use (metro). What would be the best way to get DCE, all my js files in a single folder, and not have webpack process it?
    s
    i
    • 3
    • 32
  • i

    iari

    05/07/2020, 8:11 PM
    all of the models right now are heavily annotated with backend-stuff (jpa, java validation, spring data, hibernate...)
    t
    a
    • 3
    • 13
  • s

    Sebastien Leclerc Lavallee

    05/08/2020, 4:44 AM
    I’m trying to generate a typed definition file ( typescript ) for my multi platform KotlinJS code. I wasn’t successful with any of the 2 plugins I found. Any of you had any luck ? Do you generate .d.ts file for your Kotlin code and how? I know Kotlin 1.4 should fix this but it’s not released yet and we don’t have a specific date right now. Thanks!
    👀 1
    👍 1
    s
    t
    +2
    • 5
    • 20
  • i

    iari

    05/08/2020, 6:09 PM
    How can I implement an ErrorBoundary? I cannot find any code example or explanation on ErrorBoundaries for react. What i did find however, is this ominous class
    RComponentClassStatics
    and
    RStatics
    and some 'documentation' here: https://github.com/JetBrains/kotlin-wrappers/blob/master/kotlin-react/src/main/kotlin/react/React.kt#L63-L77 So i tried implementing it like this:
    external interface ErrorBoundaryState : RState {
        var error: Throwable?
    }
    
    class ErrorBoundary : RComponent<RProps, ErrorBoundaryState>() {
        init {
            state.error = null;
        }
    
        override fun componentDidCatch(error: Throwable, info: RErrorInfo) {
            //super.componentDidCatch(error, info)
            //state.error = error
            //state.errinfo = info
            console.log("ErrorBoundary encountered error:", error)
        }
    
        override fun RBuilder.render() {
            state.error?.let { e ->
                styledDiv {
                    h3 {
                        +"Something went wrong"
                    }
                    p {
                        +e.toString()
                    }
                }
            } ?: props.children()
        }
    
        companion object : RStatics<RProps, ErrorBoundaryState, ErrorBoundary, Nothing>(ErrorBoundary::class) {
            override var getDerivedStateFromError: ((Throwable) -> ErrorBoundaryState?)?
                get() = {
                    object : ErrorBoundaryState {
                        override var error: Throwable?
                            get() = it
                            set(value) {}
                    }
                }
                set(value) {
                }
        }
    }
    However, this fails and nothing is rendered, and I get this error: Warning: ErrorBoundary: Error boundaries should implement getDerivedStateFromError(). In that method, return a state update to display an error message or fallback UI. in ErrorBoundary in Unknown so how is this done properly?
    t
    • 2
    • 33
  • g

    Grantas33

    05/08/2020, 10:08 PM
    currently my production code crashes on safari with an error:
    Can't find variable: PushManager
    , since safari does not support PushManager API. I've declared an
    external class PushManager
    with required methods in my kotlin.js app. Inside the compiled .js bundle there is a variable assignment to a PushManager class (like a typealias), and that is the reason of the error on safari. Is there a way I could prevent this?
    t
    • 2
    • 2
  • a

    andrewreitz

    05/09/2020, 11:58 AM
    Is there a way with the js plugin to add to the package.json file that's created in
    build/js
    ?
    r
    • 2
    • 8
  • m

    Marian Schubert

    05/09/2020, 5:15 PM
    Is there some medium/big size open-source project which is using Kotlin/JS for UI?
    r
    • 2
    • 5
  • a

    aerb

    05/09/2020, 6:45 PM
    How should I go about accessing test resources from kotlin-js tests? I’m able to access normal resources by http get, but that is failing in a testing context.
    ❓ 1
    i
    • 2
    • 1
  • m

    mkosm

    05/09/2020, 6:59 PM
    I'm trying to create a Google Chromecast Custom Receiver using KotlinJS. I downloaded the chromecast-caf-receiver TypeScript declaration files from DefinitelyTyped. and converted them to Kotlin using dukat. After some modifications to get the output from dukat to compile, I came up with the attached files. Question: I need to get an instance of
    CastReceiverContext
    by calling
    cast.framework.CastReceiverContext.getInstance()
    . In order to do that, I've done this:
    external object cast {
        var framework: Framework
    }
    
    external object Framework {
        var CastReceiverContext: CastReceiverContextStatic
    }
    
    external open class CastReceiverContextStatic() {
        fun getInstance(): CastReceiverContext
    }
    
    // access it using:
    val context = cast.framework.CastReceiverContext.getInstance()
    This works, but I feel like there is a better way to do this. Is there?
    cast.zip
    r
    • 2
    • 9
  • i

    iari

    05/10/2020, 4:39 PM
    I am surprised by the lack of strong types defined for window.fetch.... it seetms, like there are no enums for request methods POST, GET, its just a string, no type defined for headers, thats just a dynamic ... am i missing something? is there any convenience method to set basic auth headers with
    window.fetch
    (... or any api available in kotlin.js), or do i really just have to configure my requests 'manually' with these weak types?
    t
    • 2
    • 2
  • i

    iari

    05/10/2020, 8:57 PM
    Could it be possible to write some code that automatically generates kotlin wrappers form typescript definitions?
    f
    • 2
    • 1
  • i

    iari

    05/10/2020, 9:35 PM
    How do i use input values in a form? when i set the
    onChangeFunction
    the event.target is of type
    EventTarget?
    which has no value field.
    t
    • 2
    • 2
  • a

    andrewreitz

    05/11/2020, 12:15 AM
    Does anyone have an example of writing to the file system in kotlin? I can’t seem to find any examples of
    require('fs').writeFile
    d
    t
    a
    • 4
    • 5
  • d

    dazza5000

    05/11/2020, 4:55 PM
    my kotlin fu is not that good - how could i Create an interface that implements onmessage and assign it to an instance of MessagePort?
    t
    • 2
    • 2
Powered by Linen
Title
d

dazza5000

05/11/2020, 4:55 PM
my kotlin fu is not that good - how could i Create an interface that implements onmessage and assign it to an instance of MessagePort?
t

turansky

05/11/2020, 5:01 PM
val messagePort:MessagePort = ...
messagePort.onmessage = { event -> println(event) }
d

dazza5000

05/11/2020, 5:02 PM
Will give this a try - thank you so much!
View count: 3