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
  • s

    Slackbot

    07/08/2021, 1:05 PM
    This message was deleted.
    r
    r
    • 3
    • 4
  • p

    Pitel

    07/08/2021, 1:08 PM
    window.customElements.define("m3-stars", Stars::class.js.unsafeCast<() -> dynamic>())
    Any idea why this fails? Browser says the second parametr is not a function. The code is from https://docs.fritz2.dev/WebComponents.html#use-webcomponents
    b
    t
    • 3
    • 2
  • м

    Марк Вавилов

    07/08/2021, 4:05 PM
    HI! How to provide an independent TS/JS project's function implementation to Kotlin? I do not understand how to do it with gradle or whatever else. Relatable stack overflow question Situation: I have a Kotlin project and I want to use a TypeScript function from an opensource app, so I copied the source code to my project. The app starts via yarn.
    b
    • 2
    • 13
  • i

    Ilya Kalibrov [JB]

    07/09/2021, 9:56 AM
    Hi, folks! We know that Kotlin/JS may lack ready-to-use samples to see what the product is capable of. Could you, please, share your thoughts in the thread :thread-please: on what samples you would expect to see in our repos. Diversity is expected 😉 Anyway, thank you for your suggestions and your time !
    👍 2
    k
    a
    +5
    • 8
    • 9
  • t

    Tristan

    07/09/2021, 6:58 PM
    Hello, I am trying to use in Android's WebView a project using Kotlin/JS. I am getting error
    method can't be invoked on a non-injected object
    Looking on Google, I found this: https://bugs.chromium.org/p/chromium/issues/detail?id=514628 So I looked into the code generated, and indeed, we are not doing what they recommend. The code generated gives:
    var tmp0_safe_receiver = Native.adOver;
    return tmp0_safe_receiver == null ? null : tmp0_safe_receiver();
    For
    external object Native {
        val adOver: (() -> Unit)?
    }
    
    Native.adOver?.invoke()
    According to the report, we should generate:
    var tmp0_safe_receiver = Native.adOver.bind(Native);
    Has it been reported yet? Is there a workaround (other than just use
    js("Native.adOver?.()")
    )
    e
    d
    • 3
    • 8
  • a

    alexandrepiveteau

    07/10/2021, 6:24 PM
    Hi ! I’m trying to create
    external
    definitions from an existing npm module, but can’t figure out something. How should the following Typescript definition be declared in Kotlin ?
    [Symbol.iterator]!: () => Iterator<string>
    t
    • 2
    • 1
  • a

    Alex Ostrovsky

    07/11/2021, 2:21 AM
    has anybody tried using this from Kotlin? https://www.npmjs.com/package/react-window-infinite-loader in the example the following code is used:
    {({ onItemsRendered, ref }) => (
    is there a way to express that in Kotlin JS?
    ✅ 1
    t
    • 2
    • 9
  • j

    Jonathan Sandusky

    07/12/2021, 6:31 PM
    Hey Gang! I was wondering if the Kotlin for Javascript is in
    stable
    The multiplatform is listed as
    alpha
    . Also, when building the application can I compile/transpile JVM and Javascript? Or is this project solely for writing in Kotlin and outputting JS, not both jvm/js?
    t
    v
    s
    • 4
    • 10
  • r

    Robert Munro

    07/13/2021, 1:45 PM
    why is the best way to inject a gradle property intokotlin JS code? e.g. for a API key?
    b
    j
    • 3
    • 19
  • a

    ankushg

    07/13/2021, 8:57 PM
    Is there any way to instruct DCE to
    keep
    everything that is annotated with
    @JsExport
    ? Right now we're manually maintaining a list in
    dceTask { keep(…) }
    , and it's kinda annoying to do so manually. I know it's possible to write some code to generate the keep declarations for us, but figured it was worth asking the broader community first 😄
    t
    c
    • 3
    • 9
  • r

    Robert Munro

    07/15/2021, 7:29 AM
    I was wondering if anyone has any suggestions to internationalise i18n a static react site? hosted on github pages ...
    t
    • 2
    • 1
  • e

    Etienne

    07/16/2021, 7:03 PM
    but no options available to to unsafe cast
    json {"key1":"value1", "key2":"value2", "key3":"value3" }
    into a Kotlin type.
    r
    t
    • 3
    • 8
  • p

    Pitel

    07/19/2021, 10:55 AM
    Is is possible to read file from filesystem in browser test?
    a
    • 2
    • 2
  • r

    Robert Jaros

    07/20/2021, 7:20 AM
    This gives me JS/IR compiler
    ClassCastException
    error on 1.5.21:
    console.log(delay(5))
    (it can be any suspending function inside
    console.log(...)
    )
    b
    i
    a
    • 4
    • 14
  • c

    CLOVIS

    07/20/2021, 12:15 PM
    Are there any official tips to reduce the executable size? I'm using React, Ktor client, KotlinX.Serialization and KotlinX.Coroutines, and the executable is ~1.9MB (in prod). I'm using the IR compiler with default configuration +
    binaries.executable()
    .
    r
    • 2
    • 2
  • d

    Dmitry Romanov [JB]

    07/20/2021, 4:46 PM
    https://blog.jetbrains.com/kotlin/2021/07/kotlin-1-5-30-m1-released/#js-source-maps Looking forward to your feedback, folks.
    ❤️ 8
    👏 1
    :thank-you: 1
    👍🏻 1
    👍 1
    n
    o
    • 3
    • 3
  • p

    Pitel

    07/21/2021, 9:20 AM
    How can I include CSS from NPM module?
    b
    • 2
    • 3
  • r

    Robert Jaros

    07/21/2021, 5:46 PM
    I'm getting an error when running suspending function (even simple
    delay()
    ) after webpack hot reload. It seems to be new issue with Kotlin JS/IR 1.5.2x or coroutines 1.5.1.
    b
    • 2
    • 15
  • s

    Slackbot

    07/22/2021, 1:46 AM
    This message was deleted.
    c
    • 2
    • 1
  • a

    aerialist

    07/22/2021, 5:52 PM
    https://twitter.com/aerialist_x/status/1418254381171068932?s=09
    🚀 1
    🎉 4
    😀 1
    c
    t
    • 3
    • 2
  • p

    Pitel

    07/23/2021, 8:10 AM
    https://developer.mozilla.org/en-US/docs/Web/API/Window/getSelection any idea why
    kotlinx.browser.window
    does not have this method?
    b
    e
    • 3
    • 3
  • p

    Pitel

    07/23/2021, 1:08 PM
    Isee there are 2 Material UI wrappers. Muirwik and kotlin-material-ui. They looks to me they are both solving the same problem. Can you help me which one to choose?
    t
    • 2
    • 10
  • l

    louiscad

    07/23/2021, 3:04 PM
    Hello, I have a regex made to match markdown links that works perfectly in Kotlin/JVM, but in JavaScript, it leads to a runtime error:
    SyntaxError: Invalid regular expression: /\[(?<text>.+)\]\((?<url>[^) ]+)(?: \"(?<title>.+)\")?\)/: Invalid escape
        at new RegExp (<anonymous>)
    Here's the source code that works in the JVM and fails in Chrome :
    //language=RegExp
    val linksRegex = """\[(?<text>.+)\]\((?<url>[^) ]+)(?: \"(?<title>.+)\")?\)""".toRegex()
    When I look at the generated JavaScript code, here's what I get:
    var tmp0_toRegex_0 = '\\[(?<text>.+)\\]\\((?<url>[^) ]+)(?: \\"(?<title>.+)\\")?\\)';
    I tried to workaround using
    js("…")
    :
    val linksRegex = js("""'\[(?<text>.+)]\((?<url>[^) ]+)(?: "(?<title>.+)")?\)'""").unsafeCast<String>().toRegex()
    Unfortunately, it then seems to strip the backslashes away as it's matching quite random strings that are not markdown-style links at all but plain English sentences. Is there a way to get that Regex to work in JS like it does in the JVM?
    e
    r
    • 3
    • 5
  • b

    bsimmons

    07/24/2021, 6:01 PM
    Hey all, going through some dependency hell. Is there any way to pin transitive depedencies or provide a yarn.lock? I'm using jsMain from a frontend web page
    t
    v
    • 3
    • 23
  • d

    David Smith

    07/26/2021, 4:35 PM
    I am starting a multi platform project and I’d like to send a javascript browser
    Event
    to the jvm backend. In javascript I might normally do something like
    JSON.parse(stringifyEvent(event))
    where
    stringifyEvent
    is a function described in https://stackoverflow.com/questions/11547672/how-to-stringify-event-object/34519193#34519193. Would I need to basically do the same solution in Kotlin or is there something a bit better, perhaps built in or a library? Alternatively is there some other method to send browser events to a jvm backend?
    v
    • 2
    • 1
  • a

    andylamax

    07/26/2021, 9:25 PM
    How do I solve this? I tried • deleting .gradle, and all build dirs without success. • Compiling with different kotlin versions (1.4.32,1.5.0,1.5.10,1.5.21) But failed. Any help is appreciated
    t
    r
    • 3
    • 10
  • n

    Nikky

    07/27/2021, 10:49 AM
    reading through "sharing code on platforms" and i see
    Kotlin doesn’t currently support sharing a source set for these combinations:
    - Several JS targets
    does that mean i cannot have eg. a "common" JS target and browser + nodejs + cordova depend on that ? i really hoped i could use expect/actual to modularize and commonize stuff
    h
    • 2
    • 3
  • n

    Nikolai Sviridov

    07/30/2021, 4:59 PM
    Hello, I got html with script based on libraries https://github.com/vasturiano/3d-force-graph and three.js. Is there a way to import such html into Kotlin/React? Or I need to write wrappers around those libraries. I have seen js libraries
    html to react
    , but at the moment I'm not succeseed in writing wrappers around them.
    t
    • 2
    • 4
  • b

    benkuly

    07/31/2021, 7:06 PM
    Hi 🙂 I use Kotlin/Js and have a npm dependency, which loads a wasm file at runtime. Is there a way to include it in Kotlin/Js tests? Maybe in Karma? The wasm file is in the node_modules directory of the package.
    n
    • 2
    • 3
  • b

    benkuly

    08/01/2021, 12:05 PM
    Is it possible to invoke a javascript function before Kotlin assigns any classes to it's internal wrappes? Background: matrix.org's olm implementation for javascript uses emscripten wasm and assigns it's classes after calling an init() function. Therefore the kotlin wrappers has unvalid references
    t
    c
    • 3
    • 7
Powered by Linen
Title
b

benkuly

08/01/2021, 12:05 PM
Is it possible to invoke a javascript function before Kotlin assigns any classes to it's internal wrappes? Background: matrix.org's olm implementation for javascript uses emscripten wasm and assigns it's classes after calling an init() function. Therefore the kotlin wrappers has unvalid references
t

turansky

08/01/2021, 2:12 PM
You can add injection right in final script
c

CLOVIS

08/01/2021, 2:31 PM
If your project uses an HTML file for startup, you can execute any JS you want before loading the Kotlin file
b

benkuly

08/01/2021, 3:17 PM
Because it's a library injecting sounds very good, but how? Or do you mean manually add it to the script? That sound hacky...
c

CLOVIS

08/01/2021, 5:13 PM
Another solution: use lambdas instead of global variables, this way the references are only created on first access
Or you might want the ‘initialize globals on first access’ or whatever the option is called (it's one of the options added with IR)
b

benkuly

08/02/2021, 6:24 AM
I don't have global variables. Just classes which are used in the main or test function. In the compiled js code there is stuff like
var Account_1 = $module$_matrix_org_olm.Account;
right after the external js module is loaded.
Account_1
is used later, but points to undefined, because
init
wasn't called before
var Account_1 = ...
. A workaround is to call
js("new Olm.Account()")
everytime I would call
Account()
, but that feels really bad.
Tried
-Xir-property-lazy-initialization
and it did not work. Still
var Account_1 = $module$_matrix_org_olm.Account;
at the beginning.
View count: 8