https://kotlinlang.org logo
Docs
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
  • s

    Samuel Cook

    11/01/2019, 12:40 AM
    Can anyone suggest a way to mock or stub an
    external class
    so that code that uses them can be unit tested?
    j
    • 2
    • 2
  • n

    Nikky

    11/05/2019, 8:15 AM
    has anyone used requirejs optimizer
    r.js
    to bundle the kotlinjs output into a single file ? ideally without the need to setup node or npm in the project
    u
    n
    • 3
    • 6
  • n

    Nikky

    11/05/2019, 1:06 PM
    Is it weird that i just want to write kotlinjs and have it bundled and optimized without having to deal with npm, webpack and configuration files written in js?
    😫 1
    👀 2
    r
    s
    p
    • 4
    • 9
  • s

    sdeleuze

    11/05/2019, 5:55 PM
    If you want to have a look to Coroutines
    Flow
    used in a Kotlin/JS application configured with
    build.gradle.kts
    and DCE without any JS configuration -> https://github.com/sdeleuze/spring-messenger/tree/step-4-kotlin-js/frontend. I hope Kotlin/JS team will update the documentation. The latest changes are going toward a good direction (getting rid of frontend plugin or JS configuration) but that's a pretty diffcult journey for now.
    p
    • 2
    • 18
  • s

    sdeleuze

    11/05/2019, 5:59 PM
    I guess Android needs also dead code removal so my hope is that the new compiler will handle that natively 🤞.
    g
    • 2
    • 1
  • c

    cjmartinkoski

    11/07/2019, 1:40 PM
    hi everyone, does someone knows a project to use KotlinJS with Angular Fw?
    r
    p
    • 3
    • 9
  • h

    hellman

    11/09/2019, 10:44 AM
    Untitled.kt
    i
    • 2
    • 21
  • h

    hellman

    11/09/2019, 10:48 AM
    I have tried with ~20 different packages, no difference. It seems impossible to import NPM packages anymore?
    j
    • 2
    • 1
  • z

    zceejkr

    11/09/2019, 7:09 PM
    Hello. I am having an issue with destructuring declarations in lambdas when compiled to javascript. To clarify:
    val lam = { (a, b) ->  
      println("$a, $b")
    }
    lam(Pair(5, 3))
    prints
    5, undefined
    But:
    val lam = { pair ->  
      val a = pair.first
      val b = pair.second
      println("$a, $b")
    }
    lam(Pair(5, 3))
    prints
    5, 3
    a
    • 2
    • 4
  • j

    JoakimForslund

    11/09/2019, 10:40 PM
    I'm confused, the result in build/distributions is a somewhat correctly looking webpackd file. However, there is no exports open what so ever and the result from importing it into a javascript project and logging the object is:
    module {__esModule: true, Symbol(Symbol.toStringTag): "Module"}
    The code that is supposted to be exported is from multiplatform common, but I also tried to export directly from the javascript target. What am I missing?
    i
    • 2
    • 66
  • a

    avijitkarmakar

    11/12/2019, 5:45 AM
    Hi..I need a help. I am creating a front end web app using Kotlin. I have checked this link of raywenderlich given below: raywenderlich.com/201669-web-app-with-kotlin-js-getting-started I have already followed this and created a single page web app. But when I am going to create another page within that project. Then it's not working properly. One more thing, I can't understand from the above link is that, how the mapping is going on with HTML and Kotlin file. Please help me.. Thanks in advance..
    i
    • 2
    • 1
  • h

    hellman

    11/14/2019, 10:55 AM
    Then you just do
    it.resume(result)
    and
    it.resumeWithException(error)
    d
    • 2
    • 2
  • e

    Esakki

    11/15/2019, 11:46 AM
    Please let me know guys
    s
    • 2
    • 2
  • u

    uliluckas

    11/15/2019, 11:02 PM
    hi all, does the new kotlin.sj gradle pluginn have a way to add to the generated package.json? I need to add the following to work around a bug in an transitively dependet npm package:
    {
      "dependencies": {
        "xpc-connection": "sandeepmistry/node-xpc-connection#26/head"
      },
      "resolutions": {
        "xpc-connection": "sandeepmistry/node-xpc-connection#26/head"
      }
    }
    i
    • 2
    • 2
  • b

    basher

    11/18/2019, 11:24 PM
    How do folks working from JavaScript interacting with Kotlin/JS libraries deal with scenarios like this? Seems there is a fair amount of mangling that happens that makes it very difficult to interact with Kotlin collections from JavaScript
    snippet.js
    e
    a
    s
    • 4
    • 11
  • b

    basher

    11/19/2019, 4:07 AM
    Is there a reason why Map and Set don't map to their JS equivalents (https://kotlinlang.org/docs/reference/js-to-kotlin-interop.html)?
    s
    • 2
    • 2
  • r

    Roy Nard

    11/19/2019, 4:46 PM
    does it makes sense to compile javascript in order to simplify development. Making code more self-documenting
    f
    • 2
    • 2
  • t

    thana

    11/20/2019, 10:11 AM
    is there an up-to-date documentation about the features of the kotlin/js-compiler? e.g. i'm still missing documentation about what i can do with webpacka and npm
    ➕ 2
    r
    r
    • 3
    • 2
  • t

    thana

    11/20/2019, 10:29 AM
    or maybe a related question what i actiually want to do: we have a multi(-gradle-)modul project targeting jvm and js. to be useful for our frtonend-team we currently build an npm module, containing all dependencies using
    npm assemble
    . We do this job manuall using the moowork npm plugin. But with 1.3.60 (and possibly already with 1.3.50) this step fails because the "main" modul's js file is packaged into a zip file. Of course i could go an unzip the file so i have the file agian but that's tedious, of course. Is there a way to leverage the new plugin's abilitys to assemble the npm package?
    a
    i
    • 3
    • 3
  • j

    Joffrey

    11/20/2019, 3:48 PM
    Hi guys, I would just like to give a bit more visibility to the following issue: https://youtrack.jetbrains.com/issue/KT-31799 This basically prevents me from writing external declarations for the
    webstomp-client
    NPM library. Kotlin just doesn't allow me to express this Javascript in a type safe way, because it believes it can't translate it to valid JS, which is not true. Is there any workaround I could use?
    t
    i
    • 3
    • 6
  • h

    hellman

    11/21/2019, 6:51 AM
    The trick is to use the same JS script as you’re running in, and catch the exception when you access
    window
    . That will throw a
    ReferenceError
    , but since that isn’t exposed to the Kotlin/JS API, you have to catch
    Throwable
    instead. Now you know if you’re running in the window or as a service worker
    a
    • 2
    • 4
  • t

    thana

    11/21/2019, 12:37 PM
    Before 1.3.50 there wasnt a way do to run tests from gradle so i i implemented that myself, manually running jest with npm in a custom gradle task. now that not necessary any more, that's cool! But there is one downside! Running jest manually i could easily start the node process with the
    --inspect-brk
    swoitch so i could debug broken testcode. Is something similar possible in 1.3.(5|6)0?
    i
    • 2
    • 2
  • h

    halirutan

    11/21/2019, 3:35 PM
    Kotlin.js Newbie question: How can I read from a local file (local to the user)? I’ve seen
    FileReader
    but I’m not sure it’s for reading local files. Is there any tutorial about this?
    d
    • 2
    • 12
  • s

    shiraji

    11/22/2019, 8:13 AM
    Hi, I have a question about KotlinJS. How can I set environment variables? I tried followings: • adding .env file • setting variables in gradle • using webpack define plugin To read the variables, I used
    process.env.MY_VAR
    . I managed to see
    process.env
    but not
    process.env.MY_VAR
    r
    h
    • 3
    • 3
  • h

    halirutan

    11/22/2019, 11:07 AM
    Using kotlin-react-app, I'm trying to create a drop-area for files. I can define a div
    div("App-header") {
                attrs.onDragOverFunction = { event -> event.preventDefault() }
                attrs.onDropFunction = ::filesDropped
    but the
    onDropFunction
    has the signature
    Event -> Unit
    . I'm trying to follow some html5 JS tutorial and to access the files that were dropped, they use
    ev.dataTransfer
    , but in Kotlin this is only available for
    DragEvent
    . The problem is that the provided
    event
    is not of type
    DragEvent
    and something like this fails
    private fun filesDropped(event: Event) {
            console.log("Files dropped")
            event.preventDefault()
            val dragEvent = event as DragEvent
            val items = dragEvent.dataTransfer?.items ?: return
    Is there a simple example/tutorial how to do this in Kotlin?
    • 1
    • 1
  • t

    thana

    11/22/2019, 12:53 PM
    a test like
    @Test
        fun testFoo() {
            val a: Long = 6
            val b: Long? = createFoo()
            assertEquals(a, b)
        }
    
        fun createFoo(): Long? = if (true) 5 else null
    fails with
    jsNodeTest
    - that makes it impossible to make use of the new features 😞
    i
    b
    d
    • 4
    • 65
  • h

    halirutan

    11/24/2019, 1:07 AM
    I used kotlin-react to prototype a small page that loads log-files and turns them into data-points. Now, I wanted to plot this with a simple line graph (the data is basically a timeseries of coordinates). I thought using some Kotlin lib that wraps around ChartsJS but of course I didn't even check if there is such a thing beforehand.
    t
    • 2
    • 2
  • h

    halirutan

    11/24/2019, 1:09 AM
    Question: Is there any Kotlin lib that I can use for creating a graph for a web-page?
    g
    r
    • 3
    • 29
  • s

    spierce7

    11/24/2019, 9:19 PM
    Can we gain access to generating typescript definitions ( https://youtrack.jetbrains.com/issue/KT-16604 ) by enabling the 1.4 preview, detailed in the 1.3.60 release notes? If so - how would I go about generating them?
    r
    • 2
    • 1
  • s

    Shan

    11/24/2019, 11:09 PM
    Anyone have difficulties defining an
    external
    class with a constructor? Getting a
    not defined
    error when trying to run tests. Though I'm unsure if this is because of how I defined the constructor, or because of something else related to the class..
    external class Keypair(keys: dynamic) {
        //omitted for brevity
    }
    and the class I am trying to get it to find with the
    external
    modifier
    export class Keypair {
      constructor(keys) {
         //omitted
      }
      //omitted
    }
    s
    t
    • 3
    • 2
Powered by Linen
Title
s

Shan

11/24/2019, 11:09 PM
Anyone have difficulties defining an
external
class with a constructor? Getting a
not defined
error when trying to run tests. Though I'm unsure if this is because of how I defined the constructor, or because of something else related to the class..
external class Keypair(keys: dynamic) {
    //omitted for brevity
}
and the class I am trying to get it to find with the
external
modifier
export class Keypair {
  constructor(keys) {
     //omitted
  }
  //omitted
}
s

Svyatoslav Kuzmich [JB]

11/25/2019, 12:51 PM
Looks like your TS class is inside a module. Do you have a
@file:JsModule
annotation?
t

turansky

11/25/2019, 11:44 PM
@Shan Your case? https://youtrack.jetbrains.com/issue/KT-31126
View count: 2